<?php

namespace App\Models;

use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Laravel\Scout\Searchable;

class Client extends Model
{
    /** @use HasFactory<\Database\Factories\ClientFactory> */
    use HasFactory;

    use Searchable;
    use Uuid;

    protected $fillable = [
        'person_id',
    ];

    protected $hidden = [
        'id',
        'person_id',
    ];

    protected function makeAllSearchableUsing(Builder $query): Builder
    {
        return $query->with('person');
    }

    public function toSearchableArray(): array
    {

        return [
            'person.full_name' => '',
            'person_addresses.address' => '',
        ];
    }

    public function person(): BelongsTo
    {
        return $this->belongsTo(\App\Models\Person\Person::class);
    }

    public function clientCases(): HasMany
    {
        return $this->hasMany(\App\Models\ClientCase::class);
    }
}
