"""
AI 应用模型
"""
from sqlalchemy import Column, String, Text, Float, Integer, Boolean, JSON

from app.base_model import BaseModel


class AIApp(BaseModel):
    """
    AI 应用
    
    支持的应用类型：
    - chat: 聊天助手
    - completion: 文本生成
    - workflow: 工作流应用
    - agent: Agent 应用（预留）
    """
    __tablename__ = "ai_app"
    
    name = Column(String(100), nullable=False, comment="应用名称")
    code = Column(String(100), unique=True, nullable=False, comment="应用编码")
    description = Column(Text, default="", comment="应用描述")
    icon = Column(String(100), default="", comment="应用图标")
    app_type = Column(String(20), default="chat", comment="应用类型: chat/completion/workflow/agent")
    status = Column(String(20), default="draft", comment="状态: draft/published/disabled")
    model_id = Column(String(21), nullable=True, index=True, comment="默认模型ID（逻辑外键关联ai_llm_model）")
    system_prompt = Column(Text, default="", comment="系统提示词")
    temperature = Column(Float, default=0.7, comment="温度参数")
    top_p = Column(Float, default=1.0, comment="top_p 参数")
    max_tokens = Column(Integer, default=2048, comment="最大输出 Token")
    workflow_definition = Column(JSON, default=dict, comment="工作流定义")
    opening_statement = Column(Text, default="", comment="开场白")
    suggested_questions = Column(JSON, default=list, comment="建议问题列表")
    is_public = Column(Boolean, default=False, comment="是否公开")
    conversation_count = Column(Integer, default=0, comment="对话数量")
    message_count = Column(Integer, default=0, comment="消息数量")
