<?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_demand', function (Blueprint $table) {
            $table->bigIncrements('Dmd_Id');

            $table->unsignedBigInteger('Prop_Id');
            $table->unsignedBigInteger('Owner_ID');
            $table->unsignedBigInteger('TxTy_ID');
            $table->unsignedBigInteger('FY_Id');

            $table->string('Bill_No', 30)->unique();
            $table->date('Bill_Date');
            $table->date('Due_Date');

            $table->decimal('Assessed_Area', 10, 2);
            $table->decimal('Base_Amount', 12, 2);

            $table->decimal('Rebate_Amount', 12, 2)->default(0);
            $table->decimal('Penalty_Amount', 12, 2)->default(0);

            $table->decimal('Net_Amount', 12, 2);
            $table->decimal('Arrear_Amount', 12, 2)->default(0);
            $table->decimal('Total_Amount', 12, 2);

            $table->enum('Demand_Type', ['Regular','Revised','Supplementary','Arrear'])->default('Regular');
            $table->enum('Status', ['Pending','PartPaid','Paid','Waived','Cancelled'])->default('Pending');

            $table->unsignedBigInteger('Generated_By');

            $table->string('Remark', 255)->nullable();

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

            // FK Relations
            $table->foreign('Prop_Id')->references('Prop_Id')->on('property_master');
            $table->foreign('Owner_ID')->references('Owner_ID')->on('owner_master');
            $table->foreign('TxTy_ID')->references('TxTy_ID')->on('tax_type_masters');
            $table->foreign('FY_Id')->references('FY_Id')->on('fyear_master');
            $table->foreign('Generated_By')->references('Usr_Id')->on('user_master');
        });
    }

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