from typing import Any


HIGH_RISK_KEYWORDS = ["抑郁", "自杀", "诊断", "医生", "法律", "诉讼", "离婚协议"]
PRIVACY_KEYWORDS = ["姓名", "电话", "微信", "学校", "单位", "城市", "住址", "孩子"]


def reinforce_risk(item: dict[str, Any]) -> dict[str, Any]:
    text = " ".join(
        [
            str(item.get("raw_question", "")),
            str(item.get("raw_answer", "")),
            str(item.get("normalized_question", "")),
            str(item.get("normalized_answer", "")),
        ]
    )
    risk_types = list(item.get("risk_types") or [])
    if any(keyword in text for keyword in HIGH_RISK_KEYWORDS):
        item["risk_level"] = "high" if item.get("risk_level") != "forbidden" else "forbidden"
        if "心理 / 医疗边界" not in risk_types:
            risk_types.append("心理 / 医疗边界")
    if any(keyword in text for keyword in PRIVACY_KEYWORDS):
        item["need_desensitization"] = True
        if item.get("desensitization_status") == "not_needed":
            item["desensitization_status"] = "needed"
        if "学员隐私" not in risk_types:
            risk_types.append("学员隐私")
        if item.get("risk_level") == "low":
            item["risk_level"] = "medium"
    if item.get("risk_level") not in {"low", "medium", "high", "forbidden"}:
        item["risk_level"] = "medium"
        risk_types.append("不确定风险")
    item["risk_types"] = risk_types
    return item

