<?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::table('loans', function (Blueprint $table) {

            $table->timestamp('closed_at')
                ->nullable()
                ->after('completed_at');

            $table->foreignId('closed_by')
                ->nullable()
                ->after('approved_by')
                ->constrained('users')
                ->nullOnDelete();

            $table->text('close_reason')
                ->nullable()
                ->after('admin_notes');

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('loans', function (Blueprint $table) {

            $table->dropForeign([
                'closed_by',
            ]);

            $table->dropColumn([
                'closed_at',
                'closed_by',
                'close_reason',
            ]);

        });
    }
};