<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;

class ClcDoctorChangeRequest extends Model
{
    protected $table = 'clc_doctor_change_requests';
    protected $guarded = ['id'];

    protected $casts = [
        'reviewed_at' => 'datetime',
        'consumed_at' => 'datetime',
    ];

    public function appointment()
    {
        return $this->belongsTo(ClcAppointment::class, 'appointment_id');
    }

    public function pet()
    {
        return $this->belongsTo(ClcPatient::class, 'patient_id');
    }

    public function currentDoctor()
    {
        return $this->belongsTo(ClcDoctor::class, 'current_doctor_id');
    }

    public function requestedDoctor()
    {
        return $this->belongsTo(ClcDoctor::class, 'requested_doctor_id');
    }

    public function requester()
    {
        return $this->belongsTo(\App\User::class, 'requested_by');
    }

    public function reviewer()
    {
        return $this->belongsTo(\App\User::class, 'reviewed_by');
    }

    public function scopeForBusiness($query, $businessId)
    {
        return $query->where('business_id', $businessId);
    }

    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }
}
