<?php

namespace App\Models\CRM;

use Illuminate\Database\Eloquent\Model;
use App\Models\INSURANCE\InsurancePolicy;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Entity extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = ['entityable_id', 'entityable_type'];

    public function entityable(): MorphTo
    {
        return $this->morphTo();
    }
    
    /**
     * All insurance policies that belong to this Entity.
     */
    public function insurancePolicies(): HasMany
    {
        // assumes insurance_policies.entity_id → entities.id
        return $this->hasMany(InsurancePolicy::class, 'entity_id', 'id');
    }
}
