<?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_subtopics table — sub-sections within a Course_Topic
     * containing rich HTML content (text, images, embedded video).
     */
    public function up(): void
    {
        Schema::create('self_paced_subtopics', function (Blueprint $table) {
            $table->id();

            $table->foreignId('topic_id')
                ->constrained('self_paced_topics')
                ->cascadeOnDelete();

            $table->string('title', 191);
            $table->longText('content')->nullable()->comment('Rich HTML content');
            $table->integer('sort_order')->default(0);
            $table->boolean('is_published')->default(true);

            $table->timestamps();

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

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