<?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::create('bank_accounts', function (Blueprint $table) {
            $table->id();
            // Ownership (Person-specific). Change to your actual Person table name.
            $table->foreignId('person_id')->constrained('person')->cascadeOnDelete();
            // Account details
            $table->string('bank_name', 100);
            $table->string('iban', 34)->nullable();
            $table->string('bic_swift', 11)->nullable();
            $table->string('account_number', 34)->nullable();
            $table->string('routing_number', 20)->nullable();
            $table->char('currency', 3)->default('EUR');
            $table->char('country_code', 2)->nullable();
            $table->string('holder_name', 125)->nullable();

            // Status and lifecycle
            $table->boolean('is_active')->default(true);

            // Misc
            $table->text('notes')->nullable();
            $table->json('meta')->nullable();

            // Indexes
            $table->index('person_id');
            $table->index('iban');
            $table->softDeletes();
            $table->timestamps();

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('bank_accounts');
    }
};
