<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('analytics', function (Blueprint $table) {
            $table->id();
            $table->foreignId('course_id')->constrained('courses')->cascadeOnDelete();

            $table->unsignedInteger('total_students')->default(0);
            $table->decimal('completion_rate', 5, 2)->default(0); // 0.00 - 100.00
            $table->decimal('revenue', 12, 2)->default(0);

            $table->timestamps();

            $table->unique('course_id'); // 1 analytics row per course
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('analytics');
    }
};
