<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('staff_loans', function (Blueprint $table) {
            if (!Schema::hasColumn('staff_loans', 'payment_method')) {
                $table->enum('payment_method', ['bank', 'cash'])->default('cash')->after('notes');
                $table->foreignId('bank_account_id')->nullable()->after('payment_method')->constrained('bank_accounts')->onDelete('set null');
            }
        });
    }

    public function down(): void
    {
        Schema::table('staff_loans', function (Blueprint $table) {
            if (Schema::hasColumn('staff_loans', 'payment_method')) {
                $table->dropColumn(['payment_method', 'bank_account_id']);
            }
        });
    }
};
