from __future__ import annotations

from analogai.deepthink.startup.factories.domain_service_factory import DomainServiceFactory
from analogai.deepthink.messaging.fact.services.fact_service import FactServicePort
from analogai.deepthink.messaging.fact.services.fact_statement_service import FactStatementService
from analogai.deepthink.messaging.fact.services.fact_hypothetical_statement_service import HypotheticalStatementLinkingService


class FactDomainServiceFactory(DomainServiceFactory):
    def __init__(self, fact_service: FactServicePort):
        super().__init__()
        self._fact_service = fact_service
        self._fact_statement_service = None
        self._fact_hypothetical_statement_service = None

    def get_fact_service(self) -> FactServicePort:
        return self._fact_service

    def get_direct_statement_service(self):
        statement_service = super().get_direct_statement_service()
        if self._fact_statement_service is None:
            self._fact_statement_service = FactStatementService(statement_service, self._fact_service)
        return self._fact_statement_service

    def get_hypothetical_statement_service(self):
        statement_service = super().get_hypothetical_statement_service()
        if self._fact_hypothetical_statement_service is None:
            self._fact_hypothetical_statement_service = HypotheticalStatementLinkingService(
                statement_service,
                self._fact_service,
            )
        return self._fact_hypothetical_statement_service
