from __future__ import annotations

from app.modules.agent.observability.module_trace import ModuleTrace
from app.modules.agent.intent_router_v2 import IntentRouterV2


class IntentRouterAdapter:
    def __init__(self, router: IntentRouterV2) -> None:
        self._router = router

    def route(self, user_query: str, conversation_state, repo_context, trace: ModuleTrace | None = None):
        if trace is not None:
            trace.log("started", {"question": user_query})
        result = self._router.route(user_query, conversation_state, repo_context)
        if trace is not None:
            trace.log(
                "completed",
                {
                    "intent": result.intent,
                    "sub_intent": result.query_plan.sub_intent,
                    "matched_intent_source": result.matched_intent_source,
                },
            )
        return result
