"""交叉评查 VO。"""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field


class CrossReviewTaskTenantVO(BaseModel):
    """任务评查租户展示项。"""

    tenantCode: str = Field("", description="租户编码")
    tenantName: str = Field("", description="租户名称")


class CrossReviewTaskItemVO(BaseModel):
    """任务列表项。"""

    taskId: int = Field(..., description="任务ID")
    taskName: str = Field(..., description="任务名称")
    taskType: str = Field(..., description="任务类型")
    docTypeId: int | None = Field(None, description="文档类型ID")
    docTypeCode: str | None = Field(None, description="文档类型编码")
    status: str = Field(..., description="任务状态")
    progress: float = Field(0, description="进度百分比")
    totalDocuments: int = Field(0, description="文档总数")
    completedDocuments: int = Field(0, description="已完成文档数")
    createdAt: datetime | None = Field(None, description="创建时间")
    evaluationTenants: list[CrossReviewTaskTenantVO] = Field(default_factory=list, description="评查租户列表")
    evaluationRegion: list[str] = Field(default_factory=list, description="评查租户/地区（兼容展示值）")


class CrossReviewTaskPageVO(BaseModel):
    """任务分页响应。"""

    total: int = Field(0, description="总数")
    page: int = Field(1, description="页码")
    pageSize: int = Field(20, description="每页大小")
    items: list[CrossReviewTaskItemVO] = Field(default_factory=list, description="任务列表")


class CrossReviewTaskProgressVO(BaseModel):
    """任务进度。"""

    taskId: int = Field(..., description="任务ID")
    totalDocuments: int = Field(0, description="文档总数")
    completedDocuments: int = Field(0, description="已完成文档数")
    progress: float = Field(0, description="进度百分比")


class CrossReviewTaskDocumentVO(BaseModel):
    """任务文档列表项。"""

    documentId: int = Field(..., description="文档ID")
    name: str = Field("", description="文档名称")
    documentNumber: str | None = Field(None, description="文号")
    typeId: int | None = Field(None, description="文档类型ID")
    typeName: str | None = Field(None, description="文档类型名称")
    processingStatus: str | None = Field(None, description="处理状态")
    versionNo: int = Field(1, description="版本号")
    isLatestVersion: bool = Field(True, description="是否最新版本")
    versionGroupKey: str = Field("", description="版本组Key")
    totalVersions: int = Field(1, description="版本组总版本数")
    auditStatus: int = Field(0, description="任务内完成状态")
    createdAt: datetime | None = Field(None, description="创建时间")
    fileSize: int = Field(0, description="文件大小（字节）")
    path: str | None = Field(None, description="文件存储路径")
    uploadTime: datetime | None = Field(None, description="上传时间")
    fileExt: str | None = Field(None, description="文件扩展名")
    totalEvaluationPoints: int = Field(0, description="总评查点数")
    passCount: int = Field(0, description="通过数")
    warningCount: int = Field(0, description="警告数")
    errorCount: int = Field(0, description="错误数")
    manualCount: int = Field(0, description="人工审核数")
    issueCount: int = Field(0, description="问题总数")
    warningMessages: list[str] = Field(default_factory=list, description="警告消息")
    errorMessages: list[str] = Field(default_factory=list, description="错误消息")
    issueMessages: list[str] = Field(default_factory=list, description="问题消息")
    manualMessages: list[str] = Field(default_factory=list, description="人工审核消息")
    finalScore: float = Field(0, description="最终得分")
    fullScore: float = Field(0, description="满分")
    scoreSummary: str = Field("", description="得分摘要")
    scorePercent: float = Field(0, description="得分百分比")
    historyVersions: list["CrossReviewTaskHistoryVersionVO"] = Field(default_factory=list, description="历史版本列表")


class CrossReviewTaskHistoryVersionVO(BaseModel):
    """任务文档历史版本项。"""

    documentId: int = Field(..., description="文档ID")
    name: str = Field("", description="文档名称")
    documentNumber: str | None = Field(None, description="文号")
    typeId: int | None = Field(None, description="文档类型ID")
    typeName: str | None = Field(None, description="文档类型名称")
    processingStatus: str | None = Field(None, description="处理状态")
    versionNo: int = Field(1, description="版本号")
    auditStatus: int = Field(0, description="任务内完成状态")
    createdAt: datetime | None = Field(None, description="创建时间")
    fileSize: int = Field(0, description="文件大小（字节）")
    path: str | None = Field(None, description="文件存储路径")
    uploadTime: datetime | None = Field(None, description="上传时间")
    fileExt: str | None = Field(None, description="文件扩展名")
    totalEvaluationPoints: int = Field(0, description="总评查点数")
    passCount: int = Field(0, description="通过数")
    warningCount: int = Field(0, description="警告数")
    errorCount: int = Field(0, description="错误数")
    manualCount: int = Field(0, description="人工审核数")
    issueCount: int = Field(0, description="问题总数")
    warningMessages: list[str] = Field(default_factory=list, description="警告消息")
    errorMessages: list[str] = Field(default_factory=list, description="错误消息")
    issueMessages: list[str] = Field(default_factory=list, description="问题消息")
    manualMessages: list[str] = Field(default_factory=list, description="人工审核消息")
    finalScore: float = Field(0, description="最终得分")
    fullScore: float = Field(0, description="满分")
    scoreSummary: str = Field("", description="得分摘要")
    scorePercent: float = Field(0, description="得分百分比")


class CrossReviewTaskDocumentPageVO(BaseModel):
    """任务文档分页响应。"""

    taskId: int = Field(..., description="任务ID")
    total: int = Field(0, description="总数")
    page: int = Field(1, description="页码")
    pageSize: int = Field(20, description="每页大小")
    items: list[CrossReviewTaskDocumentVO] = Field(default_factory=list, description="文档列表")


class CrossReviewPermissionVO(BaseModel):
    """是否有权确认完成。"""

    canConfirm: bool = Field(False, description="是否可以确认完成")
    reason: str = Field("", description="原因")


class CrossReviewTaskCreateVO(BaseModel):
    """创建任务结果。"""

    taskId: int = Field(..., description="任务ID")
    taskName: str = Field(..., description="任务名称")
    memberCount: int = Field(0, description="成员数")
    documentCount: int = Field(0, description="挂载文档数")


class CrossReviewTaskCompleteVO(BaseModel):
    """确认任务文档完成结果。"""

    taskId: int = Field(..., description="任务ID")
    documentId: int = Field(..., description="文档ID")
    auditStatus: int = Field(..., description="任务内完成状态")
    taskStatus: str = Field(..., description="任务状态")
    taskCompleted: bool = Field(False, description="任务是否已全部完成")


class CrossReviewProposalCreateVO(BaseModel):
    """创建提案结果。"""

    proposalId: int = Field(..., description="提案ID")
    createdAt: datetime | None = Field(None, description="创建时间")


class CrossReviewProposalVoteVO(BaseModel):
    """提案投票结果。"""

    proposalId: int = Field(..., description="提案ID")
    voterId: int = Field(..., description="投票人ID")
    voteType: str = Field(..., description="投票类型")
    proposalStatus: str = Field(..., description="提案状态")


class CrossReviewProposalCancelVO(BaseModel):
    """撤销提案结果。"""

    proposalId: int = Field(..., description="提案ID")
    status: str = Field(..., description="提案状态")


class CrossReviewProposalVoteItemVO(BaseModel):
    """提案已投票明细。"""

    voter: str = Field("", description="投票人姓名")
    voteType: str = Field(..., description="投票类型")


class CrossReviewProposalItemVO(BaseModel):
    """提案列表项。"""

    proposalId: int = Field(..., description="提案ID")
    proposalType: str = Field("review_point", description="提案类型")
    reviewPointResultId: int | None = Field(None, description="评查点结果ID")
    evaluationPointName: str = Field("", description="评查点名称")
    extractionResultText: str = Field("", description="抽取结果文本")
    proposedScore: float = Field(..., description="调整分值")
    reason: str = Field("", description="提案理由")
    proposer: str = Field("", description="提案人姓名")
    votes: list[CrossReviewProposalVoteItemVO] = Field(default_factory=list, description="已投票明细")
    agreeVoters: list[str] = Field(default_factory=list, description="同意人")
    disagreeVoters: list[str] = Field(default_factory=list, description="反对人")
    pendingVoters: list[str] = Field(default_factory=list, description="待投票人")
    canVote: bool = Field(False, description="当前用户是否可投票")
    problemMessage: str = Field("", description="问题描述")
    proposerId: int = Field(..., description="提案人ID")
    createdAt: datetime | None = Field(None, description="创建时间")
    status: str = Field("pending", description="提案状态")


class CrossReviewProposalPageVO(BaseModel):
    """提案分页结果。"""

    total: int = Field(0, description="总数")
    page: int = Field(1, description="页码")
    pageSize: int = Field(20, description="每页数量")
    items: list[CrossReviewProposalItemVO] = Field(default_factory=list, description="提案列表")


class CrossReviewPendingProposalVO(BaseModel):
    """待投票提案摘要。"""

    evaluationPointName: str = Field("", description="评查点名称")
    pendingVotersNum: int = Field(0, description="待投票人数")


class CrossReviewPendingVotesVO(BaseModel):
    """文档待投票检查结果。"""

    hasPendingVotes: bool = Field(False, description="是否存在待投票")
    pendingProposals: list[CrossReviewPendingProposalVO] = Field(default_factory=list, description="待投票提案摘要")


class CrossReviewTaskDocumentUploadVO(BaseModel):
    """交叉评查任务补传文档结果。"""

    taskId: int = Field(..., description="任务ID")
    documentId: int = Field(..., description="文档ID")
    auditStatus: int = Field(0, description="任务内评查状态")
    processingStatus: str | None = Field(None, description="文档处理状态")


class CrossReviewTaskDocumentAppendVO(BaseModel):
    """交叉评查任务文档追加附件结果。"""

    taskId: int = Field(..., description="任务ID")
    originalDocumentId: int = Field(..., description="原文档ID")
    documentId: int = Field(..., description="新版本文档ID")
    versionNo: int = Field(..., description="新版本号")
    versionGroupKey: str = Field("", description="版本组Key")
    auditStatus: int = Field(0, description="任务内评查状态")
    processingStatus: str | None = Field(None, description="文档处理状态")
