from __future__ import annotations

from dataclasses import dataclass
from typing import Protocol, TYPE_CHECKING

if TYPE_CHECKING:
    from flownet.core.request import FlownetPacket


@dataclass(frozen=True)
class EndpointRef:
    address: str
    host: str
    port: int
    uds_path: str | None = None
    host_id: str | None = None
    transport_caps: tuple[str, ...] | None = None
    shm_path: str | None = None


class PacketTransport(Protocol):
    async def send(
        self,
        address: str,
        packet: FlownetPacket,
        endpoint: EndpointRef | None = None,
    ) -> None: ...


def split_host_port(address: str) -> tuple[str, int]:
    host, port_str = address.rsplit(":", 1)
    return host, int(port_str)
