from datetime import datetime
from pydantic import BaseModel, Field
from typing import List, Optional


# 请求模型
class ModelCreateRequest(BaseModel):
    name: str = Field(..., max_length=255, description="模型名称（必填，如：yolo-v8s-car）")
    description: Optional[str] = Field(None, description="模型描述（可选）")
    is_default: Optional[bool] = Field(False, description="是否设为默认模型")


class ModelUpdateRequest(BaseModel):
    name: Optional[str] = Field(None, max_length=255, description="模型名称（可选修改）")
    description: Optional[str] = Field(None, description="模型描述（可选修改）")
    is_default: Optional[bool] = Field(None, description="是否设为默认模型（可选切换）")


# 响应模型
class ModelResponse(BaseModel):
    id: int = Field(..., description="模型ID")
    name: str = Field(..., description="模型名称")
    path: str = Field(..., description="模型文件相对路径")
    is_default: bool = Field(..., description="是否默认模型")
    description: Optional[str] = Field(None, description="模型描述")
    file_size: Optional[int] = Field(None, description="文件大小（字节）")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")

    model_config = {"from_attributes": True}


class ModelListResponse(BaseModel):
    total: int = Field(..., description="总记录数")
    models: List[ModelResponse] = Field(..., description="当前页模型列表")

    model_config = {"from_attributes": True}
