from __future__ import annotations

from fastapi import APIRouter

from app.core.api.controllers.rag_public_controller import RagPublicController
from app.schemas.rag_sessions import RagSessionJobResponse


def build_rag_public_router(controller: RagPublicController) -> APIRouter:
    router = APIRouter(tags=["rag"])

    @router.get("/api/rag/sessions/{rag_session_id}/jobs/{index_job_id}", response_model=RagSessionJobResponse)
    async def rag_session_job(rag_session_id: str, index_job_id: str) -> RagSessionJobResponse:
        return controller.get_job(rag_session_id, index_job_id)

    @router.get("/api/rag/sessions/{rag_session_id}/jobs/{index_job_id}/events")
    async def rag_session_job_events(rag_session_id: str, index_job_id: str):
        return await controller.stream_job_events(rag_session_id, index_job_id)

    return router
