"""Step definitions for TransportSelector coverage tests."""

from __future__ import annotations

from behave import given, then, when
from behave.runner import Context


@given("no transport server URL is configured")
def step_no_server_url(context: Context) -> None:
    """Prepare a scenario with no server URL (local mode)."""
    context.transport_server_url = None


@given('a server URL "{url}" is configured')
def step_server_url_configured(context: Context, url: str) -> None:
    """Prepare a scenario with a specific server URL."""
    context.transport_server_url = url


@given("an empty string server URL is configured")
def step_empty_server_url(context: Context) -> None:
    """Prepare a scenario with an empty string as server URL."""
    context.transport_server_url = ""


@when("I call TransportSelector.select with no server_url")
def step_select_no_server_url(context: Context) -> None:
    """Call TransportSelector.select() with None (no server_url)."""
    from cleveragents.a2a.transport_selector import TransportSelector

    context.transport_result = TransportSelector.select(None)


@when('I call TransportSelector.select with server_url ""')
def step_select_empty_server_url(context: Context) -> None:
    """Call TransportSelector.select() with an empty string URL (local/stdio mode)."""
    from cleveragents.a2a.transport_selector import TransportSelector

    context.transport_result = TransportSelector.select("")


@when('I call TransportSelector.select with server_url "{url}"')
def step_select_with_server_url(context: Context, url: str) -> None:
    """Call TransportSelector.select() with the given server URL."""
    from cleveragents.a2a.transport_selector import TransportSelector

    context.transport_result = TransportSelector.select(url)


@then("the returned transport should be an A2aStdioTransport instance")
def step_transport_is_stdio(context: Context) -> None:
    """Verify the result is an A2aStdioTransport instance."""
    from cleveragents.a2a.stdio_transport import A2aStdioTransport

    assert isinstance(context.transport_result, A2aStdioTransport), (
        f"Expected A2aStdioTransport, got {type(context.transport_result).__qualname__}"
    )


@then("the returned transport should be an A2aHttpTransport instance")
def step_transport_is_http(context: Context) -> None:
    """Verify the result is an A2aHttpTransport instance."""
    from cleveragents.a2a.transport import A2aHttpTransport

    assert isinstance(context.transport_result, A2aHttpTransport), (
        f"Expected A2aHttpTransport, got {type(context.transport_result).__qualname__}"
    )
