"""
知识库文档 Schema
"""
from typing import Optional, List
from datetime import datetime

from pydantic import BaseModel, Field, ConfigDict

from app.base_schema import CSTDatetime


class DocumentUploadInput(BaseModel):
    """文档上传输入（通过文件管理系统上传后传入 file_id）"""
    file_id: str = Field(..., description="文件ID（来自文件管理系统）")
    name: Optional[str] = Field(None, description="文档名称（不传则使用文件名）")


class DocumentBatchUploadInput(BaseModel):
    """批量文档上传"""
    file_ids: List[str] = Field(..., min_length=1, description="文件ID列表")


class DocumentResponse(BaseModel):
    """文档输出"""
    id: str
    knowledge_base_id: str
    file_id: Optional[str] = None
    name: str
    file_type: str = ""
    file_size: int = 0
    content_hash: str = ""
    segment_count: int = 0
    token_count: int = 0
    char_count: int = 0
    status: str = "pending"
    error_message: str = ""
    duplicate_warning: Optional[str] = None
    enabled: bool = True
    indexing_started_at: Optional[CSTDatetime] = None
    indexing_completed_at: Optional[CSTDatetime] = None
    sys_create_datetime: Optional[CSTDatetime] = None
    sys_update_datetime: Optional[CSTDatetime] = None

    model_config = ConfigDict(from_attributes=True)


class DocumentListResponse(BaseModel):
    """文档列表输出"""
    id: str
    knowledge_base_id: str
    file_id: Optional[str] = None
    name: str
    file_type: str = ""
    file_size: int = 0
    segment_count: int = 0
    token_count: int = 0
    status: str = "pending"
    duplicate_warning: Optional[str] = None
    enabled: bool = True
    sys_create_datetime: Optional[CSTDatetime] = None

    model_config = ConfigDict(from_attributes=True)
