from __future__ import annotations

from nees.types import BehaviorPlan, DecisionResult, EmotionResult, MemoryItem, NEESRequest


class LLMAdapter:
    def __init__(self, llm: str = "default") -> None:
        self._llm = llm

    @property
    def llm(self) -> str:
        return self._llm

    def generate(
        self,
        request: NEESRequest,
        decision: DecisionResult,
        behavior: BehaviorPlan,
        emotion: EmotionResult,
        memories: list[MemoryItem],
    ) -> str:
        if decision.framework == "warm_opening":
            return (
                "Hello. I am ready to help.\n"
                "Tell me what you want to work through, decide, or understand next."
            )

        if decision.framework == "high_support":
            return (
                "You sound under heavy pressure.\n"
                "Start with one grounding step: take one slow breath and name the single issue that matters most right now.\n"
                "When you are ready, send that one issue and I will help you handle it step by step."
            )

        if decision.framework == "emotional_regulation":
            return (
                f"It makes sense that this feels {emotion.state}.\n"
                "Here is a simple way forward:\n"
                "1. Name the main pressure in one sentence.\n"
                "2. Separate what you can control today from what you cannot.\n"
                "3. Take one small next action and report back if you want help refining it."
            )

        if decision.framework == "decision_matrix":
            return (
                "Use this decision frame:\n"
                "1. List your options.\n"
                "2. Score each option on impact, effort, and risk.\n"
                "3. Choose the option with the best tradeoff for your current goal.\n"
                "If you share the options, I can turn that into a concrete comparison."
            )

        context_line = ""
        if memories:
            context_line = f"Relevant context carried forward: {memories[0].content}\n"

        return (
            f"{context_line}Structured response:\n"
            f"- Goal: {decision.goal}\n"
            "- Best next move: clarify the exact outcome you want.\n"
            f"- Current message: {request.message}"
        )
