<?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\HasOne;
use Kylin\Medical\Enums\AppointmentStatus;

/**
 * 预约挂号模型
 *
 * 管理患者预约挂号信息，包括预约时间、科室、医生、状态等。
 *
 * @property string $appointment_date 预约日期
 * @property string $time_slot        时段
 * @property string $status           预约状态
 */
class Appointment extends Model
{
    protected $table = 'appointments';

    protected $fillable = [
        'patient_id',
        'doctor_id',
        'schedule_id',
        'status',
        'appointment_no',
        'fee',
        'cancelled_at',
        'cancel_reason',
    ];

    protected $casts = [
        'status' => AppointmentStatus::class,
        'fee' => 'decimal:2',
        'cancelled_at' => 'datetime',
    ];

    /**
     * 关联患者
     */
    public function patient(): BelongsTo
    {
        return $this->belongsTo(Patient::class);
    }

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

    /**
     * 关联排班
     */
    public function schedule(): BelongsTo
    {
        return $this->belongsTo(Schedule::class);
    }

    /**
     * 问诊记录
     */
    public function consultation(): HasOne
    {
        return $this->hasOne(Consultation::class);
    }
}
