"""Telegram gateway abstraction used by business services.

The concrete aiogram implementation lives in ``app.gateways.telegram``. Tests
use a fake implementation, so no real token, channel or network is required.
"""

from __future__ import annotations

from dataclasses import dataclass
from typing import Protocol


@dataclass(frozen=True, slots=True)
class BotIdentity:
    id: int
    username: str | None


@dataclass(frozen=True, slots=True)
class ChatInfo:
    chat_id: int
    title: str | None
    username: str | None
    chat_type: str


@dataclass(frozen=True, slots=True)
class ChatMemberInfo:
    status: str
    is_member: bool | None = None

    @property
    def joined(self) -> bool:
        if self.status in {"creator", "administrator", "member"}:
            return True
        if self.status == "restricted":
            return bool(self.is_member)
        return False


@dataclass(frozen=True, slots=True)
class MessageRef:
    chat_id: int
    message_id: int


class TelegramGateway(Protocol):
    async def get_me(self) -> BotIdentity: ...

    async def get_chat(self, chat_id: int) -> ChatInfo: ...

    async def get_chat_member(self, chat_id: int, user_id: int) -> ChatMemberInfo: ...

    async def send_video(
        self,
        chat_id: int,
        file_id: str,
        *,
        caption: str | None,
        thumbnail_file_id: str | None = None,
        protect_content: bool = False,
        buttons: list[tuple[str, str]] | None = None,
    ) -> MessageRef: ...

    async def send_message(
        self,
        chat_id: int,
        text: str,
        *,
        protect_content: bool = False,
        buttons: list[tuple[str, str]] | None = None,
    ) -> MessageRef: ...

    async def delete_message(self, chat_id: int, message_id: int) -> None: ...
