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

            $table->bigIncrements('Notice_Id');

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

            $table->enum('Notice_Type', [
                'Demand Notice',
                'Reminder',
                'Final Notice',
                'Defaulter Notice',
                'Summons',
                'Auction Notice',
                'Misc'
            ])->default('Demand Notice');

            $table->string('Notice_No',30)->unique();
            $table->date('Notice_Date');

            $table->enum('Channel', [
                'SMS',
                'Email',
                'Post',
                'In-Person',
                'WhatsApp',
                'Portal'
            ])->default('SMS');

            $table->text('Remark')->nullable();

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

            $table->text('Status_Remark')->nullable();

            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
            $table->softDeletes();

            $table->foreign('Prop_Id')->references('Prop_Id')->on('property_master')->onDelete('set null');
            $table->foreign('Owner_ID')->references('Owner_ID')->on('owner_master')->onDelete('set null');
            $table->foreign('Dmd_Id')->references('Dmd_Id')->on('trans_demand')->onDelete('set null');
            $table->foreign('Status')->references('Act_Id')->on('action_master')->onDelete('set null');
            $table->foreign('R_Status')->references('Act_Id')->on('action_master')->onDelete('set null');

        });
    }

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