<?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('participants', function (Blueprint $table) {
            $table->id();
            $table->string('full_name');
            $table->text('ic_number');
            $table->string('ic_number_hash', 64)->unique();
            $table->string('participant_number')->nullable();
            $table->string('category')->nullable();
            $table->string('email')->nullable();
            $table->string('phone_number')->nullable();
            $table->string('certificate_status')->default('not_downloaded');
            $table->timestamp('first_downloaded_at')->nullable();
            $table->timestamp('last_downloaded_at')->nullable();
            $table->unsignedInteger('download_count')->default(0);
            $table->foreignId('imported_by')->nullable()->constrained('users')->nullOnDelete();
            $table->unsignedBigInteger('import_batch_id')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            $table->softDeletes();

            $table->index('certificate_status');
            $table->index('category');
            $table->index('participant_number');
        });
    }

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