<?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('borrow_transactions', function (Blueprint $table) {
            // Tambahkan kolom baru jika belum ada
            if (!Schema::hasColumn('borrow_transactions', 'tanggal_perpanjangan')) {
                $table->date('tanggal_perpanjangan')->nullable()->after('tanggal_kembali');
            }
            if (!Schema::hasColumn('borrow_transactions', 'alasan_perpanjangan')) {
                $table->text('alasan_perpanjangan')->nullable()->after('tanggal_perpanjangan');
            }
            if (!Schema::hasColumn('borrow_transactions', 'perpanjangan_diajukan')) {
                $table->boolean('perpanjangan_diajukan')->default(false)->after('alasan_perpanjangan');
            }
            if (!Schema::hasColumn('borrow_transactions', 'perpanjangan_disetujui')) {
                $table->boolean('perpanjangan_disetujui')->nullable()->after('perpanjangan_diajukan');
            }
        });
    }

    public function down(): void
    {
        Schema::table('borrow_transactions', function (Blueprint $table) {
            $columns = ['tanggal_perpanjangan', 'alasan_perpanjangan', 'perpanjangan_diajukan', 'perpanjangan_disetujui'];
            foreach ($columns as $col) {
                if (Schema::hasColumn('borrow_transactions', $col)) {
                    $table->dropColumn($col);
                }
            }
        });
    }
};

