<?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_media table — video, image, PDF, and presentation
     * files attached to a Course_SubTopic for inline display.
     */
    public function up(): void
    {
        Schema::create('self_paced_media', function (Blueprint $table) {
            $table->id();

            $table->foreignId('subtopic_id')
                ->constrained('self_paced_subtopics')
                ->cascadeOnDelete();

            $table->string('title', 191)->nullable();
            $table->enum('type', ['video', 'image', 'pdf', 'presentation', 'excel']);
            $table->string('file_path');
            $table->string('file_name', 191);
            $table->unsignedBigInteger('file_size')->default(0)->comment('bytes');
            $table->string('mime_type', 100)->nullable();
            $table->integer('sort_order')->default(0);

            $table->timestamps();

            $table->index('subtopic_id');
            $table->index('type');
        });
    }

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