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

            $table->bigIncrements('Grvnc_Id');

            $table->unsignedBigInteger('Prop_Id')->nullable();
            $table->unsignedBigInteger('Owner_ID')->nullable();
            $table->unsignedBigInteger('Dmd_Id')->nullable();

            $table->string('Grvnc_No',30)->unique();
            $table->date('Grvnc_Date');

            $table->enum('Category', [
                'Wrong Assessment',
                'Wrong Usage',
                'Ownership Dispute',
                'Duplicate Demand',
                'Payment Not Updated',
                'Exemption Claim',
                'Other'
            ]);

            $table->text('Description');

            $table->unsignedBigInteger('Status')->nullable();
            $table->unsignedBigInteger('Assigned_To')->nullable();

            $table->text('Resolution')->nullable();
            $table->timestamp('Resolved_At')->nullable();

            $table->timestamps();
            $table->softDeletes();

            $table->foreign('Prop_Id')->references('Prop_Id')->on('property_master')->nullOnDelete();
            $table->foreign('Owner_ID')->references('Owner_ID')->on('owner_master')->nullOnDelete();
            $table->foreign('Dmd_Id')->references('Dmd_Id')->on('trans_demand')->nullOnDelete();

            $table->foreign('Status')->references('Act_Id')->on('action_master')->nullOnDelete();
            $table->foreign('Assigned_To')->references('Usr_Id')->on('user_master')->nullOnDelete();

        });
    }

    public function down(): void
    {
        Schema::dropIfExists('trans_grievances');
    }
};
