<?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('borrow_transactions', function (Blueprint $table) {
            if (!Schema::hasColumn('borrow_transactions', 'perpanjangan_tanggal')) {
                $table->date('perpanjangan_tanggal')->nullable()->after('tanggal_kembali');
            }
            if (!Schema::hasColumn('borrow_transactions', 'perpanjangan_alasan')) {
                $table->string('perpanjangan_alasan')->nullable()->after('perpanjangan_tanggal');
            }
            if (!Schema::hasColumn('borrow_transactions', 'perpanjangan_status')) {
                $table->string('perpanjangan_status')->nullable()->after('perpanjangan_alasan');
            }
        });
    }

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

