<?php

namespace Modules\Main\Models\Deal;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

use Modules\User\Models\User;
use Modules\User\Models\UserRole;
use Modules\User\Models\Role;

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

class DealClients extends User
{
    use Bitrixable;
    protected $table = 'deal_clients';
    protected $fillable = ['deal_id', 'client_id'];
    public function deal()
    {
        return $this->belongsTo(Deal::class);
    }

    public function client()
    {
        return $this->belongsTo(related: Client::class);
    }

    protected static function booted(): void
    {
        static::created(function (DealClients $dealClient)
        {
            UserRole::create([
                'user_id' => $dealClient->client_id,
                'role_id' => Role::CLIENT
            ]);
        });
    }

}
