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

class AlgorithmBase(BaseModel):
    name: str = Field(..., description="算法名称")
    description: Optional[str] = Field(None, description="算法描述")
    version: str = Field(..., description="算法版本")
    model_path: Optional[str] = Field(None, description="模型文件路径")
    config_path: Optional[str] = Field(None, description="配置文件路径")
    status: str = Field("inactive", description="算法状态")
    accuracy: Optional[float] = Field(None, description="算法准确率")
    detection_classes: Optional[str] = Field(None, description="检测类别")
    input_size: Optional[str] = Field(None, description="输入尺寸")
    inference_time: Optional[float] = Field(None, description="推理时间")
    is_enabled: bool = Field(True, description="是否启用")
    creator: Optional[str] = Field(None, description="创建者")
    tags: Optional[str] = Field(None, description="标签")

class AlgorithmCreate(AlgorithmBase):
    pass

class AlgorithmUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    version: Optional[str] = None
    model_path: Optional[str] = None
    config_path: Optional[str] = None
    status: Optional[str] = None
    accuracy: Optional[float] = None
    detection_classes: Optional[str] = None
    input_size: Optional[str] = None
    inference_time: Optional[float] = None
    is_enabled: Optional[bool] = None
    creator: Optional[str] = None
    tags: Optional[str] = None

class AlgorithmResponse(AlgorithmBase):
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class AlgorithmListResponse(BaseModel):
    algorithms: List[AlgorithmResponse]
    total: int
    page: int
    size: int 