<?php

namespace App\Models;

use Database\Factories\NomineeFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

#[Fillable([
    'customer_id',
    'full_name',
    'cnic',
    'phone',
    'email',
])]
class Nominee extends Model
{
    /** @use HasFactory<NomineeFactory> */
    use HasFactory;

    public const MIN_DOCUMENTS = 2;

    public const MAX_DOCUMENTS = 2;

    /**
     * @return BelongsTo<Customer, $this>
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return HasMany<NomineeDocument, $this>
     */
    public function documents(): HasMany
    {
        return $this->hasMany(NomineeDocument::class);
    }

    public function hasRequiredDocuments(): bool
    {
        return $this->documents->count() >= self::MIN_DOCUMENTS;
    }
}
