<?php

use App\Models\Exam;
use App\Models\User;
use App\Models\ExamQuestion;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('exam_answers', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(Exam::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(ExamQuestion::class)->constrained()->cascadeOnDelete();
            $table->boolean('is_correct')->default(false);
            $table->bigInteger('user_answer_option')->unsigned()->nullable();
            $table->foreign('user_answer_option')->references('id')->on('exam_question_options')->onDelete('cascade')->onUpdate('cascade');
            $table->timestamps();
        });
    }

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