"""文档 VO。"""

from pydantic import BaseModel, Field

from fastapi_modules.fastapi_leaudit.domian.vo.auditVo import AuditRunVO


class DocumentUploadVO(BaseModel):
    """文档上传响应。"""

    documentId: int = Field(..., description="LeAudit 文档ID")
    internalDocumentNo: int = Field(..., description="平台内部追踪号（兼容旧字段）")
    versionGroupKey: str = Field(..., description="文档版本归档组键")
    versionNo: int = Field(..., description="当前文档版本号")
    previousVersionId: int | None = Field(None, description="上一版本文档ID")
    rootVersionId: int = Field(..., description="文档版本链根文档ID")
    duplicateUpload: bool = Field(..., description="是否命中同名同内容的重复上传")
    fileId: int = Field(..., description="文档文件ID")
    typeId: int = Field(..., description="文档类型ID")
    typeCode: str = Field(..., description="文档类型编码")
    region: str = Field(..., description="所属地区")
    fileName: str = Field(..., description="文件名")
    ossUrl: str = Field(..., description="OSS 对象路径")
    speed: str = Field(..., description="执行速度档位：urgent/normal")
    processingStatus: str = Field(..., description="文档处理状态")
    autoRunTriggered: bool = Field(..., description="是否已自动触发评查")
    run: AuditRunVO | None = Field(None, description="自动触发后的运行信息")


class DocumentHistoryVersionVO(BaseModel):
    """历史版本摘要。"""

    documentId: int = Field(..., description="文档ID")
    fileId: int | None = Field(None, description="文件ID")
    versionNo: int = Field(..., description="版本号")
    fileName: str | None = Field(None, description="文件名")
    fileExt: str | None = Field(None, description="文件扩展名")
    processingStatus: str | None = Field(None, description="处理状态")
    runStatus: str | None = Field(None, description="最新运行状态")
    resultStatus: str | None = Field(None, description="最新结果状态")
    updatedAt: str | None = Field(None, description="更新时间")


class DocumentListItemVO(BaseModel):
    """文档列表项。"""

    documentId: int = Field(..., description="文档ID")
    internalDocumentNo: int = Field(..., description="平台内部追踪号")
    versionGroupKey: str = Field(..., description="版本归档组键")
    versionNo: int = Field(..., description="当前版本号")
    rootVersionId: int = Field(..., description="根版本文档ID")
    previousVersionId: int | None = Field(None, description="上一版本文档ID")
    typeId: int | None = Field(None, description="文档类型ID")
    typeCode: str | None = Field(None, description="文档类型编码")
    region: str = Field(..., description="区域")
    normalizedName: str | None = Field(None, description="归一化名称")
    fileId: int | None = Field(None, description="文件ID")
    fileName: str | None = Field(None, description="文件名")
    fileExt: str | None = Field(None, description="文件扩展名")
    mimeType: str | None = Field(None, description="MIME类型")
    fileSize: int | None = Field(None, description="文件大小")
    ossUrl: str | None = Field(None, description="OSS路径")
    processingStatus: str | None = Field(None, description="处理状态")
    currentRunId: int | None = Field(None, description="当前运行ID")
    runStatus: str | None = Field(None, description="当前运行状态")
    resultStatus: str | None = Field(None, description="当前结果状态")
    totalScore: float | None = Field(None, description="总分")
    passedCount: int | None = Field(None, description="通过数")
    failedCount: int | None = Field(None, description="失败数")
    skippedCount: int | None = Field(None, description="跳过数")
    updatedAt: str | None = Field(None, description="更新时间")
    hasHistory: bool = Field(False, description="是否存在历史版本")
    totalVersions: int = Field(1, description="总版本数")
    historyVersions: list[DocumentHistoryVersionVO] = Field(default_factory=list, description="历史版本摘要")


class DocumentListPageVO(BaseModel):
    """文档列表分页结果。"""

    total: int = Field(..., description="总数")
    page: int = Field(..., description="当前页")
    pageSize: int = Field(..., description="每页数量")
    totalPages: int = Field(..., description="总页数")
    documents: list[DocumentListItemVO] = Field(default_factory=list, description="文档列表")
