<?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 $name         姓名
 * @property string $title        职称
 * @property string $specialty    专长
 * @property string $introduction 简介
 */
class Doctor extends Model
{
    protected $table = 'doctors';

    protected $fillable = [
        'user_id',
        'department_id',
        'license_no',
        'practice_scope',
        'title',
        'is_licensed',
        'practice_years',
        'introduction',
    ];

    protected $casts = [
        'is_licensed' => 'boolean',
        'practice_years' => 'integer',
    ];

    /**
     * 关联用户
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(config('auth.providers.users.model', \App\Models\User::class), 'user_id');
    }

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

    /**
     * 排班
     */
    public function schedules(): HasMany
    {
        return $this->hasMany(Schedule::class);
    }
}
