<?php

namespace App\Models\Tenancy;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class VisitHistory extends Model
{
    protected $table = 'visits_history';

    protected $casts = [
        'done' => 'boolean',
        'online' => 'boolean',
    ];

    protected $hidden = [
        'planned_id',
        'extra_specialist_id',
        'extra_specialist_name',
        'creator_id',
        'type',
        'comment',
        'x_ray',
        'history_counter',
        'insurance_code',
        'registry_comment',
        'referral_id',
        'visit_goal',
        'cabinet_id',
        'registry_other',
        'is_closed',
    ];

    public function payments(): HasMany
    {
        return $this->hasMany(
            VisitPayment::class,
            'visit_id',
            'visit_id',
        );
    }

    public function clientProcedure(): HasOne
    {
        return $this->hasOne(ClientProcedure::class, 'visit_id', 'visit_id');
    }

    public function scopeByClientId(Builder $query, int $clientId): void
    {
        $query->where('client_id', $clientId);
    }
}
