<?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('intercompany_loans', function (Blueprint $table) {
            if (!Schema::hasColumn('intercompany_loans', 'payment_method')) {
                $table->enum('payment_method', ['bank', 'cash'])->default('bank')->after('terms_conditions');
                $table->foreignId('bank_account_id')->nullable()->after('payment_method')->constrained('bank_accounts')->onDelete('set null');
            }
        });
    }

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