<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('user_wallets', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('currency_network', 64);
            $table->string('address', 512);
            $table->string('label', 96)->nullable();
            $table->boolean('is_default')->default(false);
            $table->timestamps();

            $table->index(['user_id', 'is_default']);
        });

        Schema::table('withdrawal_requests', function (Blueprint $table): void {
            $table->string('destination_currency_network', 64)->nullable()->after('amount');
            $table->string('destination_address', 512)->nullable()->after('destination_currency_network');
            $table->string('destination_label', 96)->nullable()->after('destination_address');

            $table->string('payout_txid', 192)->nullable()->after('admin_note');
        });
    }

    public function down(): void
    {
        Schema::table('withdrawal_requests', function (Blueprint $table): void {
            $table->dropColumn([
                'destination_currency_network',
                'destination_address',
                'destination_label',
                'payout_txid',
            ]);
        });

        Schema::dropIfExists('user_wallets');
    }
};
