"""
CompanionRisk Taxonomy — constants and label definitions.
"""

PRIMARY_CATEGORIES = {
    "R1": "Self-harm & Suicide Risk",
    "R2": "Mental Health Misguidance",
    "R3": "Emotional Dependency & Manipulation",
    "R4": "Real-world Support Isolation",
    "R5": "Eating Disorder & Body Harm",
    "R6": "Violence & Dangerous Behavior",
    "R7": "Minor Inappropriate Intimacy",
    "R8": "Privacy Solicitation",
    "R9": "Real-life Decision Misguidance",
    "R10": "Persona Immersion Failure",
}

PRIMARY_CATEGORY_LIST = list(PRIMARY_CATEGORIES.keys())
NUM_PRIMARY = len(PRIMARY_CATEGORY_LIST)

FINE_GRAINED_LABELS = [
    "DirectEncouragement",
    "MethodFacilitation",
    "RiskNormalization",
    "Romanticization",
    "DependencyReinforcement",
    "IsolationReinforcement",
    "FalseReassurance",
    "PseudoTherapy",
    "BoundaryFailure",
    "CrisisNonResponse",
    "CoRumination",
    "ManipulativeAttachment",
    "PrivacySolicitation",
    "AgeInappropriateIntimacy",
]
NUM_FINE = len(FINE_GRAINED_LABELS)

# Fine-grained labels most missed by generic guards
HIGH_PRIORITY_LABELS = [
    "DependencyReinforcement",
    "IsolationReinforcement",
    "Romanticization",
    "BoundaryFailure",
    "CrisisNonResponse",
    "CoRumination",
]

RISK_LEVELS = {
    0: "Safe",
    1: "Mild",
    2: "Moderate",
    3: "High",
    4: "Critical",
}
NUM_RISK_LEVELS = len(RISK_LEVELS)

INTERVENTION_ACTIONS = {
    0: "PASS",
    1: "WARN",
    2: "REWRITE",
    3: "REJECT",
    4: "CRISIS",
}
NUM_ACTIONS = len(INTERVENTION_ACTIONS)
ACTION_NAME_TO_ID = {v: k for k, v in INTERVENTION_ACTIONS.items()}

# Increasing action cost: PASS=0 < WARN=1 < REWRITE=2 < REJECT=3 < CRISIS=4
ACTION_COST = {0: 0.0, 1: 0.5, 2: 1.0, 3: 2.0, 4: 3.0}

# Recommended default action per risk level (rule-based baseline reference)
DEFAULT_ACTION_BY_LEVEL = {0: 0, 1: 0, 2: 1, 3: 2, 4: 4}  # PASS, PASS, WARN, REWRITE, CRISIS


def label_to_index(label: str) -> int:
    return FINE_GRAINED_LABELS.index(label)


def category_to_index(category: str) -> int:
    return PRIMARY_CATEGORY_LIST.index(category)
