<?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('loan_repayments', function (Blueprint $table) {
            if (!Schema::hasColumn('loan_repayments', 'confirmed_by')) {
                $table->unsignedBigInteger('confirmed_by')->nullable()->after('paid_by');
            }
            if (!Schema::hasColumn('loan_repayments', 'confirmed_at')) {
                $table->timestamp('confirmed_at')->nullable()->after('confirmed_by');
            }
        });
    }

    public function down(): void
    {
        Schema::table('loan_repayments', function (Blueprint $table) {
            $table->dropColumnIfExists('confirmed_by');
            $table->dropColumnIfExists('confirmed_at');
        });
    }
};
