from __future__ import annotations

from typing import Iterable

from analogai.deepthink.application.value_objects.user_agent import UserAgent
from analogai.deepthink.messaging.question_answering.adapters.fact_search_adapter import (
    FactSearchAdapter,
)
from analogai.deepthink.messaging.fact.enums.fact_search_mode import FactSearchMode
from analogai.deepthink.messaging.question_answering.services.assembly.fact_retrieval_command import (
    FactRetrievalCommand,
)


class FactBackgroundInfoBuilder:
    def __init__(self, fact_retriever: FactSearchAdapter | None = None) -> None:
        self._fact_retriever = fact_retriever
        self._retrieval_command = FactRetrievalCommand(self._fact_retriever)

    def build_background(
        self,
        user_agent: UserAgent,
        question_text: str,
        entities: Iterable[str] | None,
        notions: Iterable | None,
        allow_question_facts: bool,
        search_mode: FactSearchMode,
        fact_lookup: dict[str, str] | None = None,
    ) -> dict[str, str]:
        return self._retrieval_command.execute(
            user_agent,
            question_text,
            entities,
            notions,
            allow_question_facts,
            search_mode,
            lookup=fact_lookup,
        )
