from __future__ import annotations

import pytest

from rabbitmq_mcp.server import call_id, get_id, search_ids


@pytest.mark.asyncio
async def test_search_ids_returns_results() -> None:
    response = await search_ids("queues", page=1, page_size=5)
    assert response["success"] is True
    result = response["result"]
    assert result["pagination"]["page"] == 1
    assert result["pagination"]["page_size"] == 5
    assert any(item["operation_id"].startswith("queues") for item in result["items"])


@pytest.mark.asyncio
async def test_get_id_returns_schema() -> None:
    response = await get_id("queues.list")
    assert response["success"] is True
    assert response["result"]["operation_id"] == "queues.list"


@pytest.mark.asyncio
async def test_get_id_unknown_returns_error() -> None:
    response = await get_id("does.not.exist")
    assert response["success"] is False
    assert response["error"]["code"] == "OPERATION_NOT_FOUND"


@pytest.mark.asyncio
async def test_call_id_requires_body_for_amqp() -> None:
    response = await call_id("amqp.publish")
    assert response["success"] is False
    assert response["error"]["code"] == "MISSING_BODY"
