"""Backward-compatible facade for building DeepthinkEngine via bootstrap."""

from typing import Optional

from analogai.deepthink.application.value_objects.llm_config import LlmConfig
from analogai.deepthink.application.value_objects.embedding_config import EmbeddingConfig
from analogai.deepthink.infrastructure.gateways.llm.gateway import LlmGateway
from analogai.deepthink.infrastructure.gateways.llm.enums.llm_provider import LlmProvider
from analogai.deepthink.application.value_objects.user_agent import UserAgent
from analogai.deepthink.presentation.preprocessing.previous_messages_stack import PreviousMessagesStack
from analogai.deepthink.messaging.question_answering.enums.synthesized_text_type import (
	SynthesizedTextType,
)
from analogai.deepthink.startup.bootstrap import create_deepthink_engine


class Deepthinker:
	"""Facade class to preserve the public API surface."""

	def __init__(
		self,
		llm_gateway_instance: Optional[LlmGateway] = None,
		llm_provider: Optional[LlmProvider] = None,
		llm_model: Optional[str] = None,
		llm_config: Optional[LlmConfig] = None,
		embedding_config: Optional[EmbeddingConfig] = None,
	):
		self._engine = create_deepthink_engine(
			llm_gateway_instance=llm_gateway_instance,
			llm_provider=llm_provider,
			llm_model=llm_model,
			llm_config=llm_config,
			embedding_config=embedding_config,
		)

	def close(self) -> None:
		self._engine.close()

	def deepthink(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
	) -> Optional[str]:
		return self._engine.deepthink(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
		)

	def chat(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
	) -> Optional[str]:
		return self._engine.chat(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
		)

	def remember(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
	) -> Optional[str]:
		return self._engine.remember(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
		)

	def search(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
		synthesized_text_type: Optional[SynthesizedTextType] = None,
	) -> Optional[str]:
		return self._engine.search(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
			synthesized_text_type=synthesized_text_type,
		)

	def generate_background_info(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
	) -> str:
		return self._engine.generate_background_info(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
		)

	def get_background_info(
		self,
		input_text: str,
		user_agent: Optional[UserAgent] = None,
		previous_messages_stack: Optional[PreviousMessagesStack] = None,
	) -> str:
		return self._engine.get_background_info(
			input_text=input_text,
			user_agent=user_agent,
			previous_messages_stack=previous_messages_stack,
		)


DeepThinker = Deepthinker
Thinker = Deepthinker



