from datetime import datetime from typing import Protocol, runtime_checkable from uuid import UUID from messenger.messaging.domain.keys import HistoryKey from messenger.messaging.domain.models import Chat, Message, Receipt from messenger.shared.application.ports import UnitOfWork @runtime_checkable class CursorCodec(Protocol): def encode(self, scope: str, key: HistoryKey) -> str: ... def decode(self, scope: str, raw: str) -> HistoryKey: ... @runtime_checkable class ChatRepository(Protocol): async def add(self, chat: Chat) -> None: ... async def get(self, chat_id: UUID) -> Chat | None: ... async def receipt( self, chat_id: UUID, sender_id: UUID, key: str, since: datetime ) -> Receipt | None: ... async def append(self, receipt: Receipt) -> None: ... @runtime_checkable class MessagingUnitOfWork(UnitOfWork, Protocol): @property def chats(self) -> ChatRepository: ... @runtime_checkable class ChatDirectory(Protocol): async def chat_for_member(self, chat_id: UUID, user_id: UUID) -> Chat | None: ... async def chats_of( self, user_id: UUID, *, after: HistoryKey | None, limit: int ) -> tuple[list[Chat], bool]: ... async def history( self, chat_id: UUID, *, after: HistoryKey | None, limit: int ) -> tuple[list[Message], bool]: ...