<?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('ticket_orders', function (Blueprint $table) {
            $table->id();
            $table->string('order_no', 64)->unique();
            $table->foreignId('player_id')->constrained('players')->cascadeOnDelete();
            $table->foreignId('draw_id')->constrained('draws')->cascadeOnDelete();
            $table->string('currency_code', 16);
            $table->bigInteger('total_bet_amount')->default(0);
            $table->bigInteger('total_rebate_amount')->default(0);
            $table->bigInteger('total_actual_deduct')->default(0);
            $table->bigInteger('total_estimated_payout')->default(0);
            $table->string('status', 32);
            $table->string('submit_source', 16)->default('h5');
            $table->string('client_trace_id', 64)->nullable();
            $table->timestamps();

            $table->index(['player_id', 'draw_id'], 'idx_ticket_orders_player_draw');
        });
    }

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