<?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
    {
        // Skip jika column sudah wujud (new migration akan recreate table)
        if (Schema::hasColumn('maklumat_buku_darjah', 'judul')) {
            return;
        }

        Schema::table('maklumat_buku_darjah', function (Blueprint $table) {
            $table->string('judul')->default('')->after('kod_buku');
            $table->unsignedInteger('jumlah')->default(0)->after('judul');
            $table->unsignedInteger('lebihan_buku')->default(0)->after('pesan_tahun');
        });
    }

    public function down(): void
    {
        Schema::table('maklumat_buku_darjah', function (Blueprint $table) {
            $table->dropColumn(['judul', 'jumlah', 'lebihan_buku']);
        });
    }
};
