<?php

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

return new class extends Migration {
    public function up()
    {
        if (Schema::hasTable('third_game_recycles')) {
            return;
        }

        Schema::create('third_game_recycles', function (Blueprint $table) {
            $table->id();
            $table->uuid('operation_id')->unique();
            $table->string('member_id', 64)->index();
            $table->string('player_id', 16);
            $table->string('status', 32)->default('pending');
            $table->decimal('game_balance', 30, 10)->nullable();
            $table->decimal('wallet_balance', 30, 10)->nullable();
            $table->text('error')->nullable();
            $table->text('resolution_remark')->nullable();
            $table->timestamp('credited_at')->nullable();
            $table->timestamps();

            $table->index(['member_id', 'status'], 'idx_third_game_recycle_member_status');
        });
    }

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