from __future__ import annotations

from fastapi import APIRouter

from app.core.api.controllers.request_controller import RequestController
from app.core.api.controllers.session_controller import SessionController
from app.core.api.controllers.stream_controller import StreamController
from app.schemas.agent_api import (
    AgentRequestCreateRequest,
    AgentRequestQueuedResponse,
    AgentRequestStateResponse,
    CreateAgentSessionRequest,
    CreateAgentSessionResponse,
)


def build_agent_public_router(
    sessions: SessionController,
    requests: RequestController,
    streams: StreamController,
) -> APIRouter:
    router = APIRouter(tags=["agent-api"])

    @router.post("/api/agent/sessions", response_model=CreateAgentSessionResponse)
    async def create_session(request: CreateAgentSessionRequest) -> CreateAgentSessionResponse:
        return await sessions.create_session(request)

    @router.post("/api/agent/requests", response_model=AgentRequestQueuedResponse)
    async def create_request(request: AgentRequestCreateRequest) -> AgentRequestQueuedResponse:
        return await requests.create_request(request)

    @router.get("/api/agent/requests/{request_id}", response_model=AgentRequestStateResponse)
    async def get_request(request_id: str) -> AgentRequestStateResponse:
        return requests.get_request(request_id)

    @router.get("/api/agent/streams/{request_id}")
    async def stream(request_id: str):
        return await streams.stream(request_id)

    return router
