<?php

use App\Enums\QuestionExplanationTypeEnum;
use App\Enums\QuestionTypeEnum;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('quiz_questions', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(\App\Models\Quiz::class, 'quiz_id')->constrained('quizzes')->cascadeOnDelete();
            $table->foreignIdFor(\App\Models\QuestionLevel::class)->nullable()->constrained('question_levels')->cascadeOnDelete();
            $table->enum('explanation_type', QuestionExplanationTypeEnum::values())->default(QuestionExplanationTypeEnum::TEXT);
            $table->integer('time_limit')->default(0); // in seconds
            $table->integer('order')->default(1);
            $table->enum('question_type', QuestionTypeEnum::values())->default(QuestionTypeEnum::MULTIPLE_CHOICE);
            $table->longText('options')->nullable();
            $table->longText('correct_answers')->nullable(); // array of correct answers
            $table->integer('score')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('quiz_questions');
    }
};
