"""
对话 Schema
"""
from typing import Optional
from datetime import datetime

from pydantic import BaseModel, Field, ConfigDict

from app.base_schema import CSTDatetime


class ConversationCreate(BaseModel):
    """创建对话"""
    app_id: str = Field(..., description="应用 ID")
    title: str = Field(default="", description="对话标题")


class ConversationUpdate(BaseModel):
    """更新对话"""
    title: Optional[str] = None
    is_pinned: Optional[bool] = None


class ConversationResponse(BaseModel):
    """对话输出"""
    id: str
    app_id: str
    app_name: str = ""
    title: str = ""
    message_count: int = 0
    total_tokens: int = 0
    is_pinned: bool = False
    sort: int = 0
    sys_create_datetime: Optional[CSTDatetime] = None
    sys_update_datetime: Optional[CSTDatetime] = None
    
    model_config = ConfigDict(from_attributes=True)


class ConversationListResponse(BaseModel):
    """对话列表输出"""
    id: str
    title: str = ""
    message_count: int = 0
    is_pinned: bool = False
    sys_update_datetime: Optional[CSTDatetime] = None
    
    model_config = ConfigDict(from_attributes=True)


class MessageResponse(BaseModel):
    """消息输出"""
    model_config = ConfigDict(from_attributes=True, protected_namespaces=())
    
    id: str
    role: str
    content: str = ""
    status: str = "completed"
    prompt_tokens: int = 0
    completion_tokens: int = 0
    total_tokens: int = 0
    model_name: str = ""
    latency: int = 0
    error_message: str = ""
    feedback: str = ""
    sys_create_datetime: Optional[CSTDatetime] = None


class SendMessageInput(BaseModel):
    """发送消息"""
    content: str = Field(..., description="消息内容")


class MessageFeedbackInput(BaseModel):
    """消息反馈"""
    feedback: str = Field(..., description="反馈: like/dislike")
