"""
LLM 模型 Schema
"""
from typing import Optional
from datetime import datetime
from decimal import Decimal

from pydantic import BaseModel, Field, ConfigDict

from app.base_schema import CSTDatetime


class ModelCreate(BaseModel):
    """创建模型"""
    model_config = ConfigDict(protected_namespaces=())
    
    provider_id: str = Field(..., description="提供商 ID")
    model_name: str = Field(..., max_length=100, description="模型名称")
    display_name: str = Field(..., max_length=100, description="显示名称")
    model_type: str = Field(default="chat", description="模型类型")
    max_tokens: int = Field(default=4096, description="最大 Token")
    context_window: int = Field(default=4096, description="上下文窗口")
    default_temperature: float = Field(default=0.7, description="默认温度")
    default_top_p: float = Field(default=1.0, description="默认 top_p")
    input_price: Decimal = Field(default=0, description="输入价格")
    output_price: Decimal = Field(default=0, description="输出价格")
    supports_vision: bool = Field(default=False, description="支持视觉")
    supports_function_call: bool = Field(default=False, description="支持函数调用")
    supports_streaming: bool = Field(default=True, description="支持流式")
    is_active: bool = Field(default=True, description="是否启用")


class ModelUpdate(BaseModel):
    """更新模型"""
    model_config = ConfigDict(protected_namespaces=())
    
    display_name: Optional[str] = None
    model_type: Optional[str] = None
    max_tokens: Optional[int] = None
    context_window: Optional[int] = None
    default_temperature: Optional[float] = None
    default_top_p: Optional[float] = None
    input_price: Optional[Decimal] = None
    output_price: Optional[Decimal] = None
    supports_vision: Optional[bool] = None
    supports_function_call: Optional[bool] = None
    supports_streaming: Optional[bool] = None
    is_active: Optional[bool] = None


class ModelResponse(BaseModel):
    """模型输出"""
    model_config = ConfigDict(from_attributes=True, protected_namespaces=())
    
    id: str
    provider_id: str
    provider_name: str = ""
    model_name: str
    display_name: str
    model_type: str = "chat"
    max_tokens: int = 4096
    context_window: int = 4096
    default_temperature: float = 0.7
    default_top_p: float = 1.0
    input_price: Decimal = Decimal(0)
    output_price: Decimal = Decimal(0)
    supports_vision: bool = False
    supports_function_call: bool = False
    supports_streaming: bool = True
    is_active: bool = True
    sort: int = 0
    sys_create_datetime: Optional[CSTDatetime] = None
    sys_update_datetime: Optional[CSTDatetime] = None


class ModelListResponse(BaseModel):
    """模型列表输出"""
    model_config = ConfigDict(from_attributes=True, protected_namespaces=())
    
    id: str
    provider_id: str
    provider_name: str = ""
    model_name: str
    display_name: str
    model_type: str = "chat"
    is_active: bool = True


class DefaultModelResponse(BaseModel):
    """默认模型信息"""
    model_config = ConfigDict(protected_namespaces=())
    
    model_name: str
    display_name: str
    model_type: str = "chat"
    max_tokens: int = 4096
    context_window: int = 4096
    supports_vision: bool = False
    supports_function_call: bool = False
    input_price: float = 0
    output_price: float = 0
