"""서비스 레지스트리 — 모든 도메인 서비스에 대한 lazy-init 진입점."""

import logging

logger = logging.getLogger("sentinel.services.registry")


class ServiceRegistry:
    """Lazy-init 서비스 레지스트리.

    ``app.state.services`` 에 할당하여 모든 route에서
    ``request.app.state.services`` 로 접근합니다.
    """

    _instance = None

    def __init__(self):
        self._gateway = None
        self._trace_analysis = None
        self._draft_service = None
        self._copilot = None
        self._governance = None

    @classmethod
    def get(cls) -> "ServiceRegistry":
        if cls._instance is None:
            cls._instance = cls()
        return cls._instance

    # -- Langfuse Gateway --
    @property
    def gateway(self):
        if self._gateway is None:
            from sentinel.integrations.langfuse_gateway import LangfuseGateway
            self._gateway = LangfuseGateway()
        return self._gateway

    # -- Trace Analysis --
    @property
    def trace_analysis(self):
        if self._trace_analysis is None:
            from sentinel.services.trace_analysis import TraceAnalysisService
            self._trace_analysis = TraceAnalysisService(self.gateway)
        return self._trace_analysis

    # -- Draft Service --
    @property
    def draft_service(self):
        if self._draft_service is None:
            from sentinel.services.draft_service import DraftService
            self._draft_service = DraftService(self.gateway)
        return self._draft_service

    # -- Copilot --
    @property
    def copilot(self):
        if self._copilot is None:
            from sentinel.services.copilot_service import CopilotService
            self._copilot = CopilotService(self.gateway, self.trace_analysis)
        return self._copilot

    # -- Governance --
    @property
    def governance(self):
        if self._governance is None:
            from sentinel.services.governance import GovernanceService
            self._governance = GovernanceService()
        return self._governance
