from __future__ import annotations

from nees.types import IntentResult, NEESRequest


class IntentExtractor:
    def detect(self, request: NEESRequest) -> IntentResult:
        text = request.message.lower()
        cues: list[str] = []

        if any(word in text for word in ("hello", "hi", "hey", "namaste")):
            cues.append("greeting_keyword")
            return IntentResult(label="greeting", confidence=0.95, cues=cues)

        if any(
            word in text
            for word in ("feel", "sad", "lost", "anxious", "confused", "overwhelmed", "stress")
        ):
            cues.append("emotion_keyword")
            return IntentResult(label="emotional_support", confidence=0.88, cues=cues)

        if any(
            phrase in text
            for phrase in ("should i", "which one", "decide", "decision", "choose", "better option")
        ):
            cues.append("decision_keyword")
            return IntentResult(label="decision_support", confidence=0.9, cues=cues)

        if "?" in text or any(
            word in text for word in ("what", "why", "how", "when", "where", "explain")
        ):
            cues.append("question_pattern")
            return IntentResult(label="factual_query", confidence=0.8, cues=cues)

        return IntentResult(label="reflection", confidence=0.6, cues=["fallback"])
