<?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('bank_accounts', function (Blueprint $table) {
            // 예금 종류
            $table->string('account_type', 30)->default('보통예금')->after('account_holder')->comment('예금종류');

            // 금액 정보
            $table->decimal('balance', 18, 2)->default(0)->after('account_name')->comment('잔액');
            $table->string('currency', 3)->default('KRW')->after('balance')->comment('통화');

            // 날짜 정보
            $table->date('opened_at')->nullable()->after('currency')->comment('개설일자');
            $table->timestamp('last_transaction_at')->nullable()->after('opened_at')->comment('최종거래일시');

            // 추가 정보
            $table->string('branch_name', 100)->nullable()->after('last_transaction_at')->comment('지점명');
            $table->text('memo')->nullable()->after('branch_name')->comment('메모');

            // 정렬 순서
            $table->unsignedInteger('sort_order')->default(0)->after('is_primary')->comment('정렬순서');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('bank_accounts', function (Blueprint $table) {
            $table->dropColumn([
                'account_type',
                'balance',
                'currency',
                'opened_at',
                'last_transaction_at',
                'branch_name',
                'memo',
                'sort_order',
            ]);
        });
    }
};
