<?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_clients', function (Blueprint $table) {
            $table->id();
            $table->foreignId('bank_id')->constrained()->cascadeOnDelete();
            $table->morphs('client'); // creates client_id and client_type columns
            $table->string('relationship_type')->default('local'); // can be 'local' or 'specialization name', etc.
            $table->timestamps();

            // Ensure one bank per client
            $table->unique(['client_id', 'client_type', 'relationship_type']);
        });
    }

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