<?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('pengerjaan_ujian', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ujian_id')->constrained('ujian')->cascadeOnDelete();
            $table->foreignId('siswa_id')->constrained('siswa')->cascadeOnDelete();
            $table->timestamp('waktu_mulai')->nullable();
            $table->timestamp('waktu_selesai')->nullable();
            $table->enum('status', ['belum', 'sedang', 'selesai', 'direset'])->default('belum');
            $table->integer('jumlah_pelanggaran')->default(0);
            $table->boolean('is_locked')->default(false);
            $table->text('catatan_reset')->nullable();
            $table->timestamps();

            $table->unique(['ujian_id', 'siswa_id']);
            $table->index('ujian_id');
            $table->index('siswa_id');
            $table->index('status');
        });
    }

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