"""mgf-livepush typed errors.

All subclass ``mgf.common.exceptions.AppError`` so a consumer's
top-level handler treats them uniformly (rule EH-01).
"""

from __future__ import annotations

from mgf.common.exceptions import AppError

__all__ = ["CapExceededError", "LivePushError"]


class LivePushError(AppError):
    """Base class for every mgf-livepush error."""


class CapExceededError(LivePushError):
    """The per-key connection-slot cap is exhausted.

    The caller should refuse the new stream (HTTP 429). Carries the
    ``slot_key`` + ``cap`` for logging / the ``Retry-After`` response.
    """

    def __init__(self, slot_key: str, cap: int) -> None:
        self.slot_key = slot_key
        self.cap = cap
        super().__init__(
            f"live-push slot cap of {cap} concurrent connections exceeded for {slot_key!r}"
        )
