<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('draw_result_batches', function (Blueprint $table) {
            $table->id();
            $table->foreignId('draw_id')->constrained('draws')->cascadeOnDelete();
            $table->unsignedInteger('result_version');
            $table->string('source_type', 16)->comment('rng|manual');
            $table->string('rng_seed_hash', 128)->nullable();
            $table->text('raw_seed_encrypted')->nullable();
            $table->string('status', 32);
            $table->foreignId('created_by')->nullable()->constrained('admin_users')->nullOnDelete();
            $table->foreignId('confirmed_by')->nullable()->constrained('admin_users')->nullOnDelete();
            $table->timestamp('confirmed_at')->nullable();
            $table->timestamps();

            $table->unique(['draw_id', 'result_version'], 'uk_draw_result_batches_draw_version');
        });
    }

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