<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('joint_account_members', function (Blueprint $table) {
            $table->id();
            $table->foreignId('joint_account_id')->constrained()->onDelete('cascade');
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('role')->default('member'); // owner, member
            $table->string('status')->default('pending'); // pending, active, removed
            $table->string('permissions')->default('readonly'); // readonly, readwrite, full
            $table->timestamps();
            
            // Each user can only be a member of a specific joint account once
            $table->unique(['joint_account_id', 'user_id']);
        });
    }

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