<?php

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
    {
        if (!Schema::hasTable('exams')) {
            Schema::create('exams', function (Blueprint $table) {
                $table->id();
                $table->string('title');
                $table->text('description')->nullable();
                $table->text('instructions')->nullable();
                $table->unsignedInteger('duration_minutes');
                $table->unsignedInteger('passing_score'); // Percentage (0-100)
                $table->unsignedInteger('max_attempts')->default(3);
                $table->string('category')->nullable();
                $table->timestamp('available_from')->nullable();
                $table->timestamp('available_until')->nullable();
                $table->boolean('is_active')->default(true);
                $table->timestamps();
                
                $table->index('category');
                $table->index(['available_from', 'available_until']);
                $table->index('is_active');
            });
        }
    }

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