<?php

declare(strict_types=1);

namespace Kylin\Medical\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 排班模型
 *
 * 管理医生排班信息，包括出诊日期、时段、号源数量等。
 *
 * @property string $schedule_date 排班日期
 * @property string $time_slot     时段
 * @property int    $max_patients  最大号源数
 * @property int    $current_count 已预约数
 */
class Schedule extends Model
{
    protected $table = 'schedules';

    protected $fillable = [
        'doctor_id',
        'department_id',
        'date',
        'time_slot',
        'quota',
        'remaining',
        'fee',
        'status',
    ];

    protected $casts = [
        'date' => 'date',
        'quota' => 'integer',
        'remaining' => 'integer',
        'fee' => 'decimal:2',
        'status' => 'boolean',
    ];

    /**
     * 关联医生
     */
    public function doctor(): BelongsTo
    {
        return $this->belongsTo(Doctor::class);
    }

    /**
     * 关联科室
     */
    public function department(): BelongsTo
    {
        return $this->belongsTo(Department::class);
    }

    /**
     * 挂号记录
     */
    public function appointments(): HasMany
    {
        return $this->hasMany(Appointment::class);
    }
}
