from __future__ import annotations

from fastapi import FastAPI

from app.main import create_app


def _route_map(app: FastAPI) -> set[tuple[str, str]]:
    routes: set[tuple[str, str]] = set()
    for route in app.routes:
        methods = getattr(route, "methods", set()) or set()
        for method in methods:
            if method in {"HEAD", "OPTIONS"}:
                continue
            routes.add((method, route.path))
    return routes


def test_route_map_exposes_current_api_and_hides_legacy_index_routes() -> None:
    app = create_app()
    route_map = _route_map(app)

    assert ("POST", "/api/agent/sessions") in route_map
    assert ("POST", "/api/agent/requests") in route_map
    assert ("GET", "/api/agent/requests/{request_id}") in route_map
    assert ("GET", "/api/agent/streams/{request_id}") in route_map

    assert ("GET", "/api/rag/sessions/{rag_session_id}/jobs/{index_job_id}") in route_map
    assert ("GET", "/api/rag/sessions/{rag_session_id}/jobs/{index_job_id}/events") in route_map

    assert ("POST", "/api/index/snapshot") not in route_map
    assert ("POST", "/api/index/changes") not in route_map
    assert ("GET", "/api/index/jobs/{index_job_id}") not in route_map
    assert ("GET", "/api/index/jobs/{index_job_id}/events") not in route_map
    assert ("POST", "/internal/rag/index/snapshot") not in route_map
    assert ("POST", "/internal/rag/index/changes") not in route_map
    assert ("GET", "/internal/rag/index/jobs/{index_job_id}") not in route_map
    assert ("POST", "/internal/rag/retrieve") not in route_map
    assert ("POST", "/internal/rag-repo/webhook") not in route_map
    assert ("POST", "/api/agent/sessions/{session_id}/rag") not in route_map
    assert ("POST", "/api/agent/sessions/{session_id}/reset") not in route_map
    assert ("POST", "/api/rag/sessions") not in route_map
    assert ("POST", "/api/rag/sessions/{rag_session_id}/changes") not in route_map
