<?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('joint_accounts', function (Blueprint $table) {
            $table->id();
            $table->string('account_name');
            $table->string('account_number')->unique();
            $table->text('description')->nullable();
            $table->decimal('balance', 15, 2)->default(0.00);
            $table->decimal('minimum_approval_amount', 15, 2)->default(100.00);
            $table->enum('status', ['active', 'suspended', 'closed'])->default('active');
            $table->enum('approval_type', ['any_member', 'majority', 'all_members', 'specific_amount'])->default('majority');
            $table->unsignedBigInteger('created_by');
            $table->timestamps();

            $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
            $table->index(['status', 'created_at']);
        });
    }

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