"""Transport ABC - mesajların nasıl iletildiğini tanımlar."""

from abc import ABC, abstractmethod
from typing import Iterator

from .message import Message


class Transport(ABC):
    # --- messaging ---

    @abstractmethod
    def send(self, tunnel: str, msg: Message) -> None:
        """Mesajı tunnel'daki herkese gönder (gönderen hariç)."""

    @abstractmethod
    def receive(self, tunnel: str, agent: str, from_: str | None = None) -> Message | None:
        """Mailbox'tan en eski mesajı al ve sil. from_ verilirse sadece o göndericiden. Yoksa None."""

    @abstractmethod
    def listen(self, tunnel: str, agent: str, from_: str | None = None) -> Iterator[Message]:
        """Mailbox'ı sürekli dinle (blocking generator). from_ ile filtrele."""

    # --- tunnel management ---

    @abstractmethod
    def create(self, tunnel: str, creator: str) -> None:
        """Tunnel oluştur. creator otomatik admin + member."""

    @abstractmethod
    def join(self, tunnel: str, agent: str) -> None:
        """Tunnel'a katıl (member olarak)."""

    @abstractmethod
    def leave(self, tunnel: str, agent: str) -> None:
        """Tunnel'dan ayrıl."""

    @abstractmethod
    def promote(self, tunnel: str, agent: str) -> None:
        """Agent'ı admin yap."""

    @abstractmethod
    def demote(self, tunnel: str, agent: str) -> None:
        """Agent'ın admin yetkisini kaldır."""

    # --- queries ---

    @abstractmethod
    def members(self, tunnel: str) -> list[str]:
        """Tunnel üyelerini listele."""

    @abstractmethod
    def admins(self, tunnel: str) -> list[str]:
        """Tunnel adminlerini listele."""

    @abstractmethod
    def is_admin(self, tunnel: str, agent: str) -> bool:
        """Agent admin mi?"""

    @abstractmethod
    def tunnels(self) -> list[str]:
        """Mevcut tunnel'ları listele."""
