<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('withdrawals', function (Blueprint $table) {
            // 카드 관련 필드 추가
            $table->unsignedBigInteger('card_id')->nullable()->after('bank_account_id')->comment('카드 ID');
            $table->string('merchant_name', 100)->nullable()->after('client_name')->comment('가맹점명 (카드 결제시)');
            $table->timestamp('used_at')->nullable()->after('withdrawal_date')->comment('사용일시 (카드 결제시)');

            // 인덱스
            $table->index('card_id', 'idx_card');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('withdrawals', function (Blueprint $table) {
            $table->dropIndex('idx_card');
            $table->dropColumn(['card_id', 'merchant_name', 'used_at']);
        });
    }
};
