from typing import Optional
from pydantic import BaseModel, Field
from app.schemas.base import BaseModelSchema

class KnowledgeBaseBase(BaseModel):
    name: str = Field(..., description="知识库名称")
    collection_name: str = Field(..., description="Milvus集合名称")
    description: Optional[str] = Field(None, description="描述")
    status: Optional[str] = Field("normal", description="状态")

class KnowledgeBaseCreate(KnowledgeBaseBase):
    """创建知识库请求参数"""
    dimension: int = Field(768, description="向量维度，默认768")

class KnowledgeBaseUpdate(BaseModel):
    """更新知识库请求参数"""
    name: Optional[str] = None
    description: Optional[str] = None
    status: Optional[str] = None

class DescriptionUpdate(BaseModel):
    """仅更新描述（保留原有兼容性）"""
    description: str

from datetime import datetime

class KnowledgeBaseResponse(BaseModelSchema):
    """知识库响应模型"""
    id: str
    name: str
    collection_name: str
    description: Optional[str]
    status: str
    document_count: int
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True
        json_encoders = {
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S") if v else None
        }
