<?php

namespace Modules\Main\Models\Deal;

use Modules\User\Models\User;

use Modules\Main\Models\Agent\Agent;
use Modules\Bitrix\Traits\Bitrixable;

class Client extends User
{
    use Bitrixable;
    protected $table = 'users';
    public function toSearchableArray()
    {
        return [
            'name' => $this->name,
            'phone' => $this->price,
            'email' => $this->email,
        ];
    }
    public function deals()
    {
        return $this->hasManyThrough(
            Deal::class
            ,
            DealClients::class
            ,
            ''
            ,
            'id'
            ,
            'id'
            ,
            'deal_id'
        );
    }
    public function dealsWithContracts()
    {
        return $this->hasManyThrough(Deal::class, DealClients::class)->whereHas('contracts');
    }
    public function ofAgent(Agent $agent)
    {
        return $this->deals->where('agent_id', $agent->id);
    }
}
