from __future__ import annotations

from nees.types import DecisionResult, EmotionResult, IntentResult, MemoryItem


class DecisionEngine:
    def decide(
        self,
        intent: IntentResult,
        emotion: EmotionResult,
        memories: list[MemoryItem],
    ) -> DecisionResult:
        if emotion.urgency == "high":
            return DecisionResult(
                category="stabilize",
                framework="high_support",
                goal="Reduce intensity and keep the response safe and grounded.",
                system_prompt="Acknowledge distress, avoid overload, give one stabilizing next step.",
            )

        if intent.label == "greeting":
            return DecisionResult(
                category="engage",
                framework="warm_opening",
                goal="Open the interaction clearly and invite the user's real need.",
                system_prompt="Respond warmly and ask one useful follow-up question.",
            )

        if intent.label == "decision_support":
            return DecisionResult(
                category="guide_choice",
                framework="decision_matrix",
                goal="Help the user compare options and reach a decision.",
                system_prompt="Structure tradeoffs, criteria, and next action.",
            )

        if intent.label == "emotional_support":
            return DecisionResult(
                category="support",
                framework="emotional_regulation",
                goal="Reflect the user's state and provide grounded support.",
                system_prompt="Acknowledge feelings, normalize, then offer one focused action.",
            )

        if memories:
            return DecisionResult(
                category="continue_context",
                framework="contextual_answer",
                goal="Use prior context to maintain continuity.",
                system_prompt="Incorporate the most relevant prior context before answering.",
            )

        return DecisionResult(
            category="answer",
            framework="structured_answer",
            goal="Provide a concise and useful answer.",
            system_prompt="Answer clearly and keep the structure explicit.",
        )
