"""
rejection.py — Shared rejection override computation.

Computes structured prompt override actions from rejection tags.
Used by review_server.py (runtime) and test helpers (testing).
"""


def compute_rejection_overrides(tags: list[str], spoiler_word: str = "") -> dict:
    """Compute prompt override actions from structured rejection tags.

    Args:
        tags: List of rejection tag IDs.
        spoiler_word: Exclusion word for narrative_spoiler tag.

    Returns:
        Dict of override keys to be stored in gate_results.last_rejection.overrides.
    """
    overrides = {}
    for tag in tags:
        if tag == "wrong_prop":
            overrides["inject_prop_ref"] = True
            overrides["prop_recency_text"] = "[HEAVY WEIGHT: Character interacting with exact prop shown in reference]"
        elif tag == "narrative_spoiler":
            if spoiler_word:
                overrides["negative_prompt"] = f"NEGATIVE PROMPT: {spoiler_word}. EXPLICIT RULE: {spoiler_word} must NOT be visible."
        elif tag == "continuity_drift":
            overrides["inject_n1_frame"] = True
            overrides["n1_frame_text"] = "[SPATIAL LAYOUT REFERENCE ONLY] MATCH PREVIOUS SHOT BLOCKING. DO NOT copy pixel details, lighting, or style."
        elif tag == "too_clean":
            overrides["temp_delta"] = -0.15
            overrides["texture_modifiers"] = "(grime, sweat, dirt, highly detailed texture: 1.4)"
        elif tag == "wrong_camera":
            overrides["shot_type_override"] = True
        elif tag == "wrong_expression":
            overrides["inject_expression_ref"] = True
            overrides["expression_override_text"] = "[EXPRESSION OVERRIDE: Character's face must exactly match the injected emotion reference.]"
    return overrides
