"""规则配置页聚合 VO。"""

from pydantic import BaseModel, Field


class RuleConfigPackVO(BaseModel):
    """规则配置页的单个 pack。"""

    packId: int = Field(..., description="pack 标识，当前等于二级分组ID")
    groupId: int = Field(..., description="二级分组ID")
    rootGroupId: int | None = Field(None, description="一级分组ID")
    bindingId: int | None = Field(None, description="当前命中的规则集绑定ID")
    ruleSetId: int | None = Field(None, description="命中的规则集ID")
    ruleType: str | None = Field(None, description="规则类型编码")
    ruleName: str | None = Field(None, description="规则集名称")
    currentVersionId: int | None = Field(None, description="规则集当前版本ID")
    fallbackVersionId: int | None = Field(None, description="规则集回退版本ID")
    resolvedVersionId: int | None = Field(None, description="当前实际使用的版本ID")
    hasUsableVersion: bool = Field(False, description="是否存在可用规则版本")
    usableRuleCount: int = Field(0, description="可用规则数")
    documentTypeId: int | None = Field(None, description="文档类型ID")
    documentType: str = Field("", description="文档类型名称")
    moduleType: str = Field("", description="模块名称")
    mainType: str = Field("", description="一级业务类型名称")
    subtype: str = Field("", description="二级业务子类型名称")
    yamlText: str = Field("", description="当前规则 YAML 正文")
    sourceStatus: str = Field(..., description="ready/empty/missing")


class RuleConfigPackRuleSummaryVO(BaseModel):
    """规则列表页使用的轻量规则摘要。"""

    id: str = Field(..., description="规则内部ID")
    ruleId: str = Field(..., description="规则编码")
    name: str = Field(..., description="规则名称")
    group: str = Field("", description="规则分组")
    risk: str = Field("medium", description="风险等级")
    score: str = Field("0", description="分值")
    type: str = Field("deterministic", description="规则类型")
    checkTypes: list[str] = Field(default_factory=list, description="阶段检查类型")
    logic: str = Field("", description="组合逻辑")
    subRules: list[dict] = Field(default_factory=list, description="阶段摘要")
    subRuleIds: list[str] = Field(default_factory=list, description="子规则编码")
    scope: list[str] = Field(default_factory=list, description="规则作用域")
    dependencies: list[str] = Field(default_factory=list, description="依赖字段")
    stageCount: int = Field(0, description="阶段数量")
    appliesIn: list[str] = Field(default_factory=list, description="适用阶段")
    prompt: str = Field("", description="AI 提示词")
    description: str = Field("", description="规则说明")


class RuleConfigPackListVO(BaseModel):
    """规则列表页使用的轻量 pack。"""

    packId: int = Field(..., description="pack 标识，当前等于二级分组ID")
    groupId: int = Field(..., description="二级分组ID")
    rootGroupId: int | None = Field(None, description="一级分组ID")
    bindingId: int | None = Field(None, description="当前命中的规则集绑定ID")
    ruleSetId: int | None = Field(None, description="命中的规则集ID")
    ruleType: str | None = Field(None, description="规则类型编码")
    ruleName: str | None = Field(None, description="规则集名称")
    currentVersionId: int | None = Field(None, description="规则集当前版本ID")
    fallbackVersionId: int | None = Field(None, description="规则集回退版本ID")
    resolvedVersionId: int | None = Field(None, description="当前实际使用的版本ID")
    hasUsableVersion: bool = Field(False, description="是否存在可用规则版本")
    usableRuleCount: int = Field(0, description="可用规则数")
    documentTypeId: int | None = Field(None, description="文档类型ID")
    documentType: str = Field("", description="文档类型名称")
    moduleType: str = Field("", description="模块名称")
    mainType: str = Field("", description="一级业务类型名称")
    subtype: str = Field("", description="二级业务子类型名称")
    yamlName: str = Field("", description="YAML metadata.name")
    sourceStatus: str = Field(..., description="ready/empty/missing")
    rules: list[RuleConfigPackRuleSummaryVO] = Field(default_factory=list, description="规则摘要列表")
