from app.services.expense_claim_risk_flags import dedupe_claim_risk_flags


def test_dedupe_claim_risk_flags_keeps_highest_severity_for_same_route_issue() -> None:
    flags = [
        {
            "severity": "high",
            "label": "多城市行程待说明",
            "message": "检测到本次差旅涉及深圳多个目的地，但当前报销事由未说明中转原因。",
            "item_ids": ["route-1", "route-2"],
            "business_stage": "reimbursement",
        },
        {
            "severity": "medium",
            "label": "多城市行程缺少说明中风险",
            "message": "本次报销识别到多城市行程，但事由中未说明中转、多地拜访或改签原因。",
            "item_ids": ["route-2"],
            "business_stage": "reimbursement",
        },
    ]

    deduped = dedupe_claim_risk_flags(flags)

    assert [flag["label"] for flag in deduped] == ["多城市行程待说明"]


def test_dedupe_claim_risk_flags_keeps_distinct_item_risks() -> None:
    flags = [
        {
            "severity": "high",
            "label": "住宿金额超出报销标准",
            "message": "第一张住宿票超出住宿标准。",
            "item_id": "hotel-1",
            "business_stage": "reimbursement",
        },
        {
            "severity": "medium",
            "label": "住宿金额超出报销标准",
            "message": "第二张住宿票超出住宿标准。",
            "item_id": "hotel-2",
            "business_stage": "reimbursement",
        },
    ]

    deduped = dedupe_claim_risk_flags(flags)

    assert [flag["item_id"] for flag in deduped] == ["hotel-1", "hotel-2"]
