from __future__ import annotations

from fastapi import APIRouter

from app.core.api.application.session_bootstrap_service import SessionBootstrapService
from app.core.api.application.request_service import RequestService
from app.core.api.application.stream_service import StreamService
from app.core.api.controllers.request_controller import RequestController
from app.core.api.controllers.rag_public_controller import RagPublicController
from app.core.api.controllers.session_controller import SessionController
from app.core.api.controllers.stream_controller import StreamController
from app.core.api.public_router import build_agent_public_router
from app.core.api.rag_public_router import build_rag_public_router
from app.core.rag.module import RagModule


class ApiModule:
    def __init__(
        self,
        session_bootstrap: SessionBootstrapService,
        requests: RequestService,
        streams: StreamService,
        rag: RagModule,
    ) -> None:
        self._sessions = SessionController(session_bootstrap)
        self._requests = RequestController(requests)
        self._streams = StreamController(streams)
        self._rag_public = RagPublicController(rag)

    def public_router(self) -> APIRouter:
        router = APIRouter()
        router.include_router(
            build_agent_public_router(
                sessions=self._sessions,
                requests=self._requests,
                streams=self._streams,
            )
        )
        router.include_router(build_rag_public_router(self._rag_public))
        return router
