<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Claim extends Model
{
    use HasFactory;

    protected $fillable = [
        // Policy Holder
        'policy_holder_id',

        // Deceased Details
        'deceased_full_name',
        'deceased_national_id',
        'deceased_gender',
        'deceased_date_of_birth',
        'deceased_type',

        // Claim Details
        'date_of_death',
        'cause_of_death',
        'relationship_to_policyholder',
        'amount_claimed',
        'reference_number',

        // Claimant Details (ANY PERSON)
        'claimant_full_name',
        'claimant_national_id',
        'claimant_phone',
        'claimant_address',

        // Status & Remarks
        'claim_status',
        'remarks',

        // Audit / Actions
        'created_by',
        'updated_by',
        'action_by',
        'action_at',
        'action_comment',

        'reviewed_by',
        'reviewed_at',
        'review_comment',
    ];

    /* ================= RELATIONSHIPS ================= */

    // Policy Holder
    public function policyHolder()
    {
        return $this->belongsTo(Member::class, 'policy_holder_id');
    }

    // Claim Documents
    public function documents()
    {
        return $this->hasMany(ClaimDocument::class, 'claim_id');
    }

    // User who CREATED the claim
    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    // User who LAST UPDATED the claim
    public function updatedBy()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    // User who APPROVED / REJECTED
    public function actionBy()
    {
        return $this->belongsTo(User::class, 'action_by');
    }
}
