<?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('transfer_orders', function (Blueprint $table) {
            $table->id();
            $table->string('transfer_no', 64)->unique();
            $table->foreignId('player_id')->constrained('players')->cascadeOnDelete();
            $table->string('direction', 16);
            $table->string('currency_code', 16);
            $table->bigInteger('amount');
            $table->string('idempotent_key', 64)->unique();
            $table->string('status', 32);
            $table->json('external_request_payload')->nullable();
            $table->json('external_response_payload')->nullable();
            $table->string('external_ref_no', 64)->nullable();
            $table->string('fail_reason', 255)->nullable();
            $table->timestamp('finished_at')->nullable();
            $table->timestamps();

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

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