<?php

declare(strict_types=1);

namespace Kylin\Medical\Models;

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

/**
 * 处方明细模型
 *
 * 管理处方中的药品明细，包括药品、用量、用法、天数等。
 *
 * @property int    $drug_id     药品ID
 * @property string $dosage      用量
 * @property string $usage       用法
 * @property int    $days        天数
 * @property int    $quantity    数量
 */
class PrescriptionItem extends Model
{
    protected $table = 'prescription_items';

    public $timestamps = false;

    protected $fillable = [
        'prescription_id',
        'drug_id',
        'dosage',
        'frequency',
        'days',
        'usage_method',
        'remark',
    ];

    protected $casts = [
        'days' => 'integer',
    ];

    /**
     * 关联处方
     */
    public function prescription(): BelongsTo
    {
        return $this->belongsTo(Prescription::class);
    }

    /**
     * 关联药品
     */
    public function drug(): BelongsTo
    {
        return $this->belongsTo(Drug::class);
    }
}
