<?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_exam_questions table — the question bank for a Course.
     * Each question has four options (A-D) and a designated correct answer.
     */
    public function up(): void
    {
        Schema::create('self_paced_exam_questions', function (Blueprint $table) {
            $table->id();

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

            $table->text('question_text');
            $table->text('option_a');
            $table->text('option_b');
            $table->text('option_c');
            $table->text('option_d');
            $table->enum('correct_answer', ['A', 'B', 'C', 'D']);
            $table->text('explanation')->nullable();

            $table->integer('sort_order')->default(0);
            $table->boolean('is_active')->default(true);

            $table->timestamps();

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

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