"""A2A server-mode HTTP transport stub.

Every method raises :class:`A2aNotAvailableError`.  When server mode is
implemented (separate project) the concrete transport will replace this stub.
"""

from __future__ import annotations

import structlog

from cleveragents.a2a.errors import A2aNotAvailableError
from cleveragents.a2a.models import A2aRequest, A2aResponse

logger: structlog.stdlib.BoundLogger = structlog.get_logger(__name__)

_SERVER_MODE_MSG = (
    "A2A HTTP transport is not available in local mode"
    " - server mode will be implemented as a separate project"
)


class A2aHttpTransport:
    """Stub HTTP transport — all mutating methods raise on invocation."""

    def send(self, request: A2aRequest) -> A2aResponse:
        """Send an A2A request over HTTP.

        Always raises :class:`A2aNotAvailableError` in local mode.
        """
        if not isinstance(request, A2aRequest):
            raise TypeError("request must be an A2aRequest instance")
        logger.warning(
            "%s (method=%s)",
            _SERVER_MODE_MSG,
            request.method,
        )
        raise A2aNotAvailableError(
            _SERVER_MODE_MSG,
            details={"method": request.method},
        )

    def connect(self, base_url: str) -> None:
        """Open a connection to the A2A server.

        Always raises :class:`A2aNotAvailableError` in local mode.
        """
        if not base_url or not isinstance(base_url, str):
            raise ValueError("base_url must be a non-empty string")
        logger.warning("%s (url=%s)", _SERVER_MODE_MSG, base_url)
        raise A2aNotAvailableError(
            _SERVER_MODE_MSG,
            details={"base_url": base_url},
        )

    def disconnect(self) -> None:
        """Close the connection to the A2A server.

        Always raises :class:`A2aNotAvailableError` in local mode.
        """
        logger.warning(_SERVER_MODE_MSG)
        raise A2aNotAvailableError(_SERVER_MODE_MSG)

    def is_connected(self) -> bool:
        """Return connection status.  Always ``False`` in local mode."""
        return False


__all__ = [
    "A2aHttpTransport",
]
