from pydantic import BaseModel, Field


class RagDatasetItemVO(BaseModel):
    id: int = Field(...)
    name: str = Field(...)
    description: str = Field("")
    area: str = Field("")
    isPublic: bool = Field(False)
    isDefault: bool = Field(False)
    documentCount: int = Field(0)
    totalChunks: int = Field(0)
    status: int = Field(1)
    sortOrder: int = Field(0)
    createdAt: int = Field(0)
    updatedAt: int = Field(0)
    appId: int | None = Field(default=None)
    appName: str = Field("")
    appIsDefault: bool = Field(False)


class RagDatasetPageVO(BaseModel):
    data: list[RagDatasetItemVO] = Field(default_factory=list)
    total: int = Field(0)


class RagDatasetDetailVO(BaseModel):
    id: int = Field(...)
    name: str = Field(...)
    description: str = Field("")
    area: str = Field("")
    isPublic: bool = Field(False)
    isDefault: bool = Field(False)
    status: int = Field(1)
    documentCount: int = Field(0)
    totalChunks: int = Field(0)
    chunkMaxSize: int = Field(800)
    chunkMinSize: int = Field(20)
    sortOrder: int = Field(0)
    retrievalModel: dict = Field(default_factory=dict)
    createdAt: int = Field(0)
    updatedAt: int = Field(0)
    appId: int | None = Field(default=None)
    appName: str = Field("")
    appIsDefault: bool = Field(False)


class RagDatasetDocumentItemVO(BaseModel):
    id: int = Field(...)
    datasetId: int = Field(...)
    name: str = Field(...)
    fileType: str = Field("")
    fileSize: int = Field(0)
    chunkCount: int = Field(0)
    indexingStatus: str = Field("waiting")
    error: str = Field("")
    enabled: bool = Field(True)
    hitCount: int = Field(0)
    createdBy: int | None = Field(None)
    createdAt: int = Field(0)
    updatedAt: int = Field(0)


class RagDatasetDocumentPageVO(BaseModel):
    data: list[RagDatasetDocumentItemVO] = Field(default_factory=list)
    total: int = Field(0)
    page: int = Field(1)
    limit: int = Field(20)
    hasMore: bool = Field(False)


class RagDatasetUploadDocumentVO(BaseModel):
    document: dict = Field(default_factory=dict)
    batch: str = Field("")


class RagDatasetBatchDeleteFailedItemVO(BaseModel):
    id: int = Field(...)
    name: str = Field("")
    reason: str = Field("")


class RagDatasetBatchDeleteResultVO(BaseModel):
    result: str = Field("success")
    requestedCount: int = Field(0)
    deletedCount: int = Field(0)
    skippedCount: int = Field(0)
    deletedIds: list[int] = Field(default_factory=list)
    skipped: list[RagDatasetBatchDeleteFailedItemVO] = Field(default_factory=list)


class RagDatasetSegmentItemVO(BaseModel):
    id: str = Field(...)
    position: int = Field(0)
    documentId: str = Field("")
    content: str = Field("")
    wordCount: int = Field(0)
    hitCount: int = Field(0)
    enabled: bool = Field(True)
    status: str = Field("completed")
    createdAt: int = Field(0)


class RagDatasetSegmentPageVO(BaseModel):
    data: list[RagDatasetSegmentItemVO] = Field(default_factory=list)
    total: int = Field(0)
    limit: int = Field(20)
    hasMore: bool = Field(False)


class RagDatasetRetrieveDocumentVO(BaseModel):
    id: str = Field("")
    dataSourceType: str = Field("upload_file")
    name: str = Field("")
    docType: str | None = Field(default=None)


class RagDatasetRetrieveSegmentVO(BaseModel):
    id: str = Field(...)
    position: int = Field(0)
    documentId: str = Field("")
    content: str = Field("")
    answer: str = Field("")
    wordCount: int = Field(0)
    hitCount: int = Field(0)
    enabled: bool = Field(True)
    status: str = Field("completed")
    createdAt: int = Field(0)
    document: RagDatasetRetrieveDocumentVO | None = Field(default=None)


class RagDatasetRetrieveRecordVO(BaseModel):
    segment: RagDatasetRetrieveSegmentVO = Field(...)
    score: float = Field(0.0)


class RagDatasetRetrieveResponseVO(BaseModel):
    query: dict = Field(default_factory=dict)
    records: list[RagDatasetRetrieveRecordVO] = Field(default_factory=list)
