"""Govdoc 规则结果模型 —— govdoc_rule_results 表。"""

from __future__ import annotations

from sqlalchemy import BigInteger, Integer, Numeric, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from fastapi_common.fastapi_common_web.models import BaseModel


class GovdocRuleResult(BaseModel):
    """公文规则执行结果明细表。"""

    __tablename__ = "govdoc_rule_results"

    Id: Mapped[int] = mapped_column("id", BigInteger, primary_key=True, autoincrement=True)
    runId: Mapped[int] = mapped_column("run_id", BigInteger, comment="关联 govdoc_runs.id")

    # 规则标识
    ruleId: Mapped[str] = mapped_column("rule_id", String(128), comment="规则标识")
    ruleName: Mapped[str | None] = mapped_column("rule_name", String(256), comment="规则名称")
    severity: Mapped[str | None] = mapped_column("severity", String(32), comment="严重等级：error/warning/info")
    category: Mapped[str | None] = mapped_column("category", String(128), comment="规则分类")

    # 结果内容
    message: Mapped[str | None] = mapped_column("message", Text, comment="结果描述")
    suggestion: Mapped[str | None] = mapped_column("suggestion", Text, comment="修改建议")
    actual: Mapped[str | None] = mapped_column("actual", Text, comment="实际值")
    expected: Mapped[str | None] = mapped_column("expected", Text, comment="期望值")
    evidence: Mapped[str | None] = mapped_column("evidence", Text, comment="证据文本")

    # 文档定位
    paragraphIndex: Mapped[int | None] = mapped_column("paragraph_index", Integer, comment="段落索引")
    paragraphText: Mapped[str | None] = mapped_column("paragraph_text", Text, comment="段落原文")
    locationPath: Mapped[str | None] = mapped_column("location_path", String(512), comment="文档结构位置路径")

    # 判定
    result: Mapped[str] = mapped_column("result", String(32), default="pass", comment="执行结果：pass/fail/skipped/error")
    skipReason: Mapped[str | None] = mapped_column("skip_reason", Text, comment="跳过原因，仅 skipped/error 时使用")
    score: Mapped[float | None] = mapped_column("score", Numeric(10, 2), comment="本条得分")
