from datetime import datetime, timedelta, timezone

_PRESENCE_TIMEOUT = timedelta(seconds=90)
_last_seen: datetime | None = None


def mark_ninja_seen() -> None:
    global _last_seen
    _last_seen = datetime.now(timezone.utc)


def ninja_is_connected(now: datetime | None = None) -> bool:
    if _last_seen is None:
        return False
    current = now or datetime.now(timezone.utc)
    return current - _last_seen <= _PRESENCE_TIMEOUT


def reset_ninja_presence() -> None:
    global _last_seen
    _last_seen = None
