<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $driver = DB::getDriverName();

        if (in_array($driver, ['mysql', 'mariadb'], true)) {
            DB::statement("ALTER TABLE loans MODIFY status ENUM('draft','pending','approved','rejected','closed') NOT NULL DEFAULT 'draft'");
        }
    }

    public function down(): void
    {
        $driver = DB::getDriverName();

        if (in_array($driver, ['mysql', 'mariadb'], true)) {
            DB::table('loans')->where('status', 'draft')->update(['status' => 'pending']);
            DB::statement("ALTER TABLE loans MODIFY status ENUM('pending','approved','rejected','closed') NOT NULL DEFAULT 'pending'");
        }
    }
};
