<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Creates the self_paced_topics table — top-level sections within a Course.
     */
    public function up(): void
    {
        Schema::create('self_paced_topics', function (Blueprint $table) {
            $table->id();

            $table->foreignId('course_id')
                ->constrained('self_paced_courses')
                ->cascadeOnDelete();

            $table->string('title', 191);
            $table->text('description')->nullable();
            $table->integer('sort_order')->default(0);
            $table->boolean('is_published')->default(true);

            $table->timestamps();

            $table->index('course_id');
            $table->index('sort_order');
        });
    }

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