from __future__ import annotations

from rabbitmq_mcp.registry import build_request, get_operation, search_operations
from rabbitmq_mcp.registry import operation_schema


def test_registry_contains_queues_list() -> None:
    operation = get_operation("queues.list")
    assert operation.method == "get"
    assert operation.path == "/api/queues"


def test_search_operations_finds_queues() -> None:
    results = search_operations("queues", limit=5)
    operation_ids = {item["operation_id"] for item in results}
    assert "queues.list" in operation_ids


def test_build_request_encodes_path_params() -> None:
    operation = get_operation("queues.get_by_params")
    path, query = build_request(
        operation,
        path_params={"vhost": "/", "name": "a/b"},
        query_params={"page": 1},
    )
    assert path == "/api/queues/%2F/a%2Fb"
    assert query == {"page": 1}


def test_registry_includes_amqp() -> None:
    operation = get_operation("amqp.publish")
    assert operation.protocol == "amqp"


def test_operation_schema_includes_output_schema() -> None:
    operation = get_operation("overview.list")
    schema = operation_schema(operation)
    assert "output_schema" in schema
    assert schema["output_schema"] != {"type": "object"}
