import re

# Contrastive patterns where "not" must be ignored
CONTRASTIVE_PATTERNS = [
    r"\bnot only\b",
    r"\bnot just\b",
    r"\bnot merely\b",
    r"\bnot to mention\b",
    r"\bnot that\b",
    r"\bnot because\b"
]


def has_contrastive_pattern(text: str) -> bool:
    t = text.lower()
    for pat in CONTRASTIVE_PATTERNS:
        if re.search(pat, t):
            return True
    return False


def is_negated_intent(text: str, intent_verbs: list[str]) -> bool:
    """
    Args:
        text: input sentence
        intent_verbs: list of verbs that triggered the rule
                      e.g. ["recommend", "suggest"]

    Returns:
        True  -> valid negation of intent detected
        False -> no valid negation
    """
    t = text.lower()

    # Step 1: ignore contrastive constructions
    if has_contrastive_pattern(t):
        return False

    # Step 2: verb-bound negation templates
    for verb in intent_verbs:
        patterns = [
            rf"\bdo not {verb}\b",
            rf"\bdoes not {verb}\b",
            rf"\bdid not {verb}\b",
            rf"\bwould not {verb}\b",
            rf"\bshould not {verb}\b",
            rf"\bcannot {verb}\b",
            rf"\bcan't {verb}\b",
            rf"\bnot {verb}\b"
        ]

        for pat in patterns:
            if re.search(pat, t):
                return True

    return False
