<?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('work_allocation_book', function (Blueprint $table) {
           $table->unsignedBigInteger('Dpt_id')->nullable()->after('WA_RefId')->index();
            $table->unsignedBigInteger('Lg_Id')->nullable()->after('Dpt_id')->index();
            $table->text('Description')->nullable()->after('WO_Date');

            // Foreign Keys
            $table->foreign('Dpt_id', 'fk_wa_dpt')
                  ->references('Dpt_id')
                  ->on('dept_master')
                  ->onDelete('restrict')
                  ->onUpdate('cascade');

            $table->foreign('Lg_Id', 'fk_wa_lg')
                  ->references('Lg_Id')
                  ->on('ledger_master')
                  ->onDelete('restrict')
                  ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('work_allocation_book', function (Blueprint $table) {
            $table->dropForeign('fk_wa_dpt');
            $table->dropForeign('fk_wa_lg');

            $table->dropColumn(['Dpt_id', 'Lg_Id', 'Description']);
        });
    }
};
