from __future__ import annotations

from app.infra.exceptions import AppError
from app.core.api.application.session_service import SessionService
from app.core.api.infrastructure.ids.session_id_factory import SessionIdFactory
from app.core.api.infrastructure.stores.in_memory_session_store import InMemorySessionStore
import pytest


def test_create_session_allows_binding_rag_at_creation_time() -> None:
    service = SessionService(store=InMemorySessionStore(), ids=SessionIdFactory())

    session = service.create("rag_123")

    assert session.session_id.startswith("as_")
    assert session.active_rag_session_id == "rag_123"
    assert session.messages == []
    assert session.conversation_state.turn_index == 0


def test_get_missing_session_raises_not_found() -> None:
    service = SessionService(store=InMemorySessionStore(), ids=SessionIdFactory())
    with pytest.raises(AppError) as exc:
        service.get("missing-session")

    assert exc.value.code == "session_not_found"
