<?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_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('draw_id')->constrained('draws')->cascadeOnDelete();
            $table->foreignId('result_batch_id')->constrained('draw_result_batches')->cascadeOnDelete();
            $table->string('prize_type', 32);
            $table->unsignedInteger('prize_index')->default(0);
            $table->char('number_4d', 4);
            $table->char('suffix_3d', 3)->nullable();
            $table->char('suffix_2d', 2)->nullable();
            $table->unsignedTinyInteger('head_digit')->nullable();
            $table->unsignedTinyInteger('tail_digit')->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->index(['draw_id', 'prize_type', 'prize_index'], 'idx_draw_result_items_draw_prize');
            $table->index(['draw_id', 'number_4d'], 'idx_draw_result_items_draw_number');
        });
    }

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