<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::create('claims', function (Blueprint $table) {
            $table->id();

            // Policy Holder (Owner of Policy)
            $table->unsignedBigInteger('policy_holder_id');



            // Deceased Details
            $table->string('deceased_full_name');
            $table->string('deceased_national_id');
            $table->enum('deceased_gender', ['Male', 'Female']);
            $table->date('deceased_date_of_birth');
            $table->enum('deceased_type', ['Policyholder', 'Dependant']);

            // Claim Details
            $table->date('date_of_death');
            $table->string('cause_of_death');
            $table->string('claimant_full_name');
            $table->string('relationship_to_policyholder');
            $table->decimal('amount_claimed', 12, 2)->nullable();
            $table->string('reference_number')->nullable();
            $table->string('claimant_national_id')->nullable();
            $table->string('claimant_phone')->nullable();
            $table->string('claimant_address')->nullable();
            $table->enum('claim_status', ['Pending', 'Approved', 'Rejected', 'Under Review'])->default('Pending');
            $table->text('remarks')->nullable();

             $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();

            $table->unsignedBigInteger('action_by')->nullable();
            $table->dateTime('action_at')->nullable();
            $table->text('action_comment')->nullable();

            
            $table->unsignedBigInteger('reviewed_by')
                  ->nullable()
                  ->after('created_by');

            $table->timestamp('reviewed_at')
                  ->nullable()
                  ->after('reviewed_by');

            $table->text('review_comment')
                  ->nullable()
                  ->after('reviewed_at');

            $table->timestamps();

            // Foreign Keys
            $table->foreign('policy_holder_id')
                ->references('id')
                ->on('members')
                ->onDelete('cascade');
        });
    }

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