<?php

namespace App\Models\INSURANCE;

use App\Enums\AddressType;
use App\Models\CRM\Entity;
use App\Models\CRM\Address;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class InsurancePolicy extends Model
{
    /** @use HasFactory<\Database\Factories\INSURANCE\InsurancePolicyFactory> */
    use HasFactory;

    protected $fillable = [
        'entity_id',
        'policy_number',
        'insurer_id',
        'commission_default_id',
        'custom_name',
        'commission_pct_default',
        'commission_pct',
        'expected_commission',
        'insured_amount',
        'premium',
        'start_date',
        'end_date',
        'status',
    ];

    protected $casts = [
        'start_date' => 'date',
        'end_date'   => 'date',
    ];

    /**
     * An InsurancePolicy belongs to an Entity.
     * This relationship allows us to access the policy holder details whether it's an Individual or Company.
     */
    public function entity(): BelongsTo
    {
        return $this->belongsTo(Entity::class, 'entity_id');
    }

    public function insurer(): BelongsTo
    {
        return $this->belongsTo(Insurer::class, 'insurer_id');
    }

    public function commissionDefault(): BelongsTo
    {
        return $this->belongsTo(CommissionDefault::class, 'commission_default_id');
    }
}
