<?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('trans_grievances', function (Blueprint $table) {

            $table->unsignedBigInteger('Generated_By')->nullable()->after('Grvnc_Id');
            $table->unsignedBigInteger('Approved_By')->nullable()->after('Generated_By');

            $table->foreign('Generated_By')
                  ->references('Usr_Id')
                  ->on('user_master')
                  ->onDelete('set null')
                  ->onUpdate('cascade');

            $table->foreign('Approved_By')
                  ->references('Usr_Id')
                  ->on('user_master')
                  ->onDelete('set null')
                  ->onUpdate('cascade');
        });
    }

    public function down(): void
    {
        Schema::table('trans_grievances', function (Blueprint $table) {

            $table->dropForeign(['Generated_By']);
            $table->dropForeign(['Approved_By']);

            $table->dropColumn(['Generated_By', 'Approved_By']);
        });
    }
};
