from __future__ import annotations

from typing import Any, Awaitable, Callable, Protocol

from flownet.v1.runtime.comm.protocol import V1Envelope


V1TransportReceiver = Callable[[V1Envelope | dict[str, Any]], Any | Awaitable[Any]]


class V1TransportBackend(Protocol):
    """Transport backend contract used by V1CommHub."""

    def register_endpoint(
        self,
        *,
        address: str,
        receiver: V1TransportReceiver,
    ) -> None: ...

    def unregister_endpoint(self, *, address: str) -> bool: ...

    async def send(self, envelope_payload: V1Envelope | dict[str, Any]) -> None: ...


__all__ = [
    "V1TransportBackend",
    "V1TransportReceiver",
]
