<?php

namespace Modules\VetClinic\Entities;

use Illuminate\Database\Eloquent\Model;

class VcDepartment extends Model
{
    protected $table = 'vc_departments';
    protected $guarded = ['id'];

    public function location()
    {
        return $this->belongsTo(VcClinicLocation::class, 'location_id');
    }

    public function doctors()
    {
        return $this->hasMany(VcDoctor::class, 'department_id');
    }

    public function assignedDoctors()
    {
        return $this->belongsToMany(VcDoctor::class, 'vc_doctor_departments', 'department_id', 'doctor_id')
                    ->withTimestamps();
    }

    public function schedules()
    {
        return $this->hasMany(VcDoctorSchedule::class, 'department_id');
    }

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

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