"""Replayable evaluation cases for the financial risk graph algorithm."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any


@dataclass(frozen=True, slots=True)
class RiskEvaluationCase:
    case_id: str
    category: str
    expected_signal: str
    expected_level: str
    description: str
    payload: dict[str, Any] = field(default_factory=dict)

    def as_dict(self) -> dict[str, Any]:
        return {
            "case_id": self.case_id,
            "category": self.category,
            "expected_signal": self.expected_signal,
            "expected_level": self.expected_level,
            "description": self.description,
            "payload": dict(self.payload),
        }


def default_risk_evaluation_cases() -> list[RiskEvaluationCase]:
    return [
        RiskEvaluationCase(
            case_id="positive_duplicate_invoice_high",
            category="positive",
            expected_signal="duplicate_invoice",
            expected_level="high",
            description="重复发票叠加高金额偏离，应输出高风险观察。",
            payload={"risk_flags": ["duplicate_invoice"], "invoice_reuse": True},
        ),
        RiskEvaluationCase(
            case_id="negative_clean_low_amount",
            category="negative",
            expected_signal="none",
            expected_level="none",
            description="低金额、无规则命中、无图谱异常，不应输出风险观察。",
            payload={"amount": 300, "risk_flags": []},
        ),
        RiskEvaluationCase(
            case_id="counterfactual_invoice_corrected",
            category="counterfactual",
            expected_signal="none",
            expected_level="none",
            description="重复票据被替换为唯一票据后，风险应消失或降级。",
            payload={"remove_duplicate_invoice": True},
        ),
        RiskEvaluationCase(
            case_id="noise_missing_employee",
            category="noise",
            expected_signal="preapproval_absent",
            expected_level="medium",
            description="缺失员工信息时允许候选观察，但不能输出强风控结论。",
            payload={"missing_fields": ["employee"], "score_cap": 69},
        ),
        RiskEvaluationCase(
            case_id="historical_false_positive_calibration",
            category="historical_false_positive",
            expected_signal="duplicate_invoice",
            expected_level="medium",
            description="历史误报率较高时进入校准抽审，不直接强拦截。",
            payload={"false_positive_rate": 0.35},
        ),
    ]
