from datetime import datetime from typing import Protocol, runtime_checkable from uuid import UUID from messenger.identity.domain.models import Session, User from messenger.shared.application.ports import UnitOfWork @runtime_checkable class UserRepository(Protocol): async def add(self, user: User) -> None: ... @runtime_checkable class SessionRepository(Protocol): async def add(self, session: Session) -> None: ... async def remove(self, token_hash: bytes) -> None: ... @runtime_checkable class IdentityUnitOfWork(UnitOfWork, Protocol): @property def users(self) -> UserRepository: ... @property def sessions(self) -> SessionRepository: ... @runtime_checkable class UserDirectory(Protocol): async def find(self, user_id: UUID) -> User | None: ... async def find_by_username(self, username: str) -> User | None: ... @runtime_checkable class SessionDirectory(Protocol): async def find(self, token_hash: bytes, now: datetime) -> Session | None: ... @runtime_checkable class SessionRevocations(Protocol): async def revoke(self, session: Session) -> None: ... async def restore(self, session: Session) -> None: ... @runtime_checkable class PasswordHasher(Protocol): async def hash(self, password: str) -> str: ... async def verify(self, password_hash: str | None, password: str) -> bool: ...