from __future__ import annotations

from app.modules.agent.llm import AgentLlmService
from app.modules.agent.prompt_loader import PromptLoader
from app.modules.rag.intent_router_v2.intent.classifier import IntentClassifierV2
from app.modules.rag.intent_router_v2.router import IntentRouterV2
from app.modules.shared.env_loader import load_workspace_env
from app.modules.shared.gigachat.client import GigaChatClient
from app.modules.shared.gigachat.settings import GigaChatSettings
from app.modules.shared.gigachat.token_provider import GigaChatTokenProvider


class GigaChatIntentRouterFactory:
    def build(self) -> IntentRouterV2:
        load_workspace_env()
        settings = GigaChatSettings.from_env()
        token_provider = GigaChatTokenProvider(settings)
        client = GigaChatClient(settings, token_provider)
        prompt_loader = PromptLoader()
        llm = AgentLlmService(client=client, prompts=prompt_loader)
        classifier = IntentClassifierV2(llm=llm)
        return IntentRouterV2(classifier=classifier)
