<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('quiz_attempts', function (Blueprint $table) {

            $table->id();

            $table->foreignId('user_id')
                ->constrained()
                ->cascadeOnDelete();

            $table->foreignId('quiz_id')
                ->constrained()
                ->cascadeOnDelete();

            $table->unsignedInteger('score')
                ->default(0);

            $table->unsignedInteger('total_points')
                ->default(0);

            $table->unsignedInteger('percentage')
                ->default(0);

            $table->json('answers')
                ->nullable();

            $table->timestamp('submitted_at');

            $table->timestamps();

        });
    }

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