"""规则 VO。"""

from pydantic import BaseModel, Field


class RuleSetVO(BaseModel):
    """规则集响应。"""

    id: int = Field(..., description="规则集ID")
    ruleType: str = Field(..., description="业务规则类型编码")
    ruleName: str = Field(..., description="规则集名称")
    domainType: str | None = Field(None, description="域类型")
    currentVersionId: int | None = Field(None, description="当前激活版本ID")
    fallbackVersionId: int | None = Field(None, description="最近一个可回退使用的已发布版本ID")
    hasUsableVersion: bool = Field(False, description="是否存在可用于上传评查的规则版本")
    usableRuleCount: int = Field(0, description="当前可用于上传评查的规则数")
    status: str = Field(..., description="draft/active/inactive/archived")


class RuleVersionVO(BaseModel):
    """规则版本响应。"""

    id: int = Field(..., description="版本ID")
    ruleSetId: int = Field(..., description="所属规则集ID")
    versionNo: str = Field(..., description="版本号")
    status: str = Field(..., description="draft/validated/published/rolled_back")
    ossUrl: str = Field(..., description="YAML 文件 OSS 地址")
    changeNote: str | None = Field(None, description="变更说明")
    publishedAt: str | None = Field(None, description="发布时间")


class RuleContentVO(BaseModel):
    """规则版本正文响应。"""

    id: int = Field(..., description="版本ID")
    ruleSetId: int = Field(..., description="所属规则集ID")
    ruleType: str = Field(..., description="规则类型编码")
    versionNo: str = Field(..., description="版本号")
    yamlText: str = Field(..., description="YAML 正文")
    ossUrl: str = Field(..., description="YAML 文件 OSS 地址")


class RuleValidationVO(BaseModel):
    """规则 YAML 校验响应。"""

    valid: bool = Field(..., description="是否校验通过")
    ruleType: str | None = Field(None, description="规则类型编码")
    ruleName: str | None = Field(None, description="规则名称")
    versionNo: str | None = Field(None, description="规则版本号")
    ruleCount: int = Field(0, description="规则总数")
    extractCount: int = Field(0, description="抽取字段总数")
    errors: list[str] = Field(default_factory=list, description="错误信息列表")


class RuleBindingVO(BaseModel):
    """规则类型绑定响应。"""

    id: int = Field(..., description="绑定ID")
    docTypeId: int = Field(..., description="文档类型ID")
    docTypeCode: str | None = Field(None, description="文档类型编码")
    ruleSetId: int = Field(..., description="规则集ID")
    ruleType: str | None = Field(None, description="规则类型编码（来自关联查询）")
    ruleName: str | None = Field(None, description="规则集名称（来自关联查询）")
    bindingMode: str = Field(..., description="绑定模式: explicit / wildcard / fallback")
    priority: int = Field(0, description="优先级")
    isActive: bool = Field(True, description="是否激活")
    note: str | None = Field(None, description="备注说明")
