from __future__ import annotations

from app.core.api.application.session_bootstrap_service import SessionBootstrapService
from app.schemas.agent_api import CreateAgentSessionRequest, CreateAgentSessionResponse


class SessionController:
    def __init__(self, service: SessionBootstrapService) -> None:
        self._service = service

    async def create_session(self, request: CreateAgentSessionRequest) -> CreateAgentSessionResponse:
        result = await self._service.create(
            project_id=request.project_id,
            files=[item.model_dump() for item in request.files],
        )
        session = result.session
        return CreateAgentSessionResponse(
            session_id=session.session_id,
            rag_session_id=session.active_rag_session_id or "",
            index_job_id=result.index_job.index_job_id,
            status=result.index_job.status,
            created_at=session.created_at,
        )
