from __future__ import annotations

from app.schemas.agent_api import (
    BindRagSessionRequest,
    BindRagSessionResponse,
    CreateAgentSessionResponse,
    ResetAgentSessionResponse,
)
from app.modules.api.application.session_service import SessionService


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

    def create_session(self) -> CreateAgentSessionResponse:
        session = self._service.create()
        return CreateAgentSessionResponse(
            session_id=session.session_id,
            active_rag_session_id=session.active_rag_session_id,
            created_at=session.created_at,
        )

    def bind_rag_session(self, session_id: str, request: BindRagSessionRequest) -> BindRagSessionResponse:
        session = self._service.bind_rag_session(session_id, request.rag_session_id)
        return BindRagSessionResponse(
            session_id=session.session_id,
            active_rag_session_id=session.active_rag_session_id,
            updated_at=session.updated_at,
        )

    def reset_session(self, session_id: str) -> ResetAgentSessionResponse:
        session = self._service.reset(session_id)
        return ResetAgentSessionResponse(
            session_id=session.session_id,
            active_rag_session_id=session.active_rag_session_id,
            status="reset",
            updated_at=session.updated_at,
        )
