<?php

declare(strict_types=1);

namespace Kylin\Medical\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Kylin\Medical\Enums\MessageType;

/**
 * 消息模型
 *
 * 管理医患沟通消息，支持文本、图片、语音等多种消息类型。
 *
 * @property string $type    消息类型
 * @property string $content 消息内容
 */
class Message extends Model
{
    protected $table = 'messages';

    public $timestamps = false;

    protected $fillable = [
        'consultation_id',
        'sender_type',
        'sender_id',
        'content',
        'type',
        'sent_at',
    ];

    protected $casts = [
        'type' => MessageType::class,
        'sent_at' => 'datetime',
    ];

    /**
     * 关联问诊
     */
    public function consultation(): BelongsTo
    {
        return $this->belongsTo(Consultation::class);
    }
}
