from pydantic import BaseModel
from typing import Optional
import uuid


class IMMessage(BaseModel):
    msg_id: str = ""
    sender: str
    receiver: str
    content: str
    msg_type: str = "chat"  # chat | image | video | system
    sender_chat_id: Optional[str] = None  # 发送方窗口 ID
    receiver_chat_id: Optional[str] = None  # 接收方窗口 ID（指定则定向，否则广播）

    def model_post_init(self, __context):
        if not self.msg_id:
            self.msg_id = uuid.uuid4().hex[:12]


class IMResponse(BaseModel):
    status: str  # "success" | "failed"
    msg_id: str
    error: Optional[str] = None
