"""Typed configuration errors for mgf-django (EH-01 / EH-08).

Both subclass ``mgf.common.exceptions.ConfigError`` (→ ``AppError``) so a
consumer's exception-translation middleware treats them uniformly, and each
carries machine-readable fields so callers route on the field, not the message.
"""

from __future__ import annotations

from mgf.common.exceptions import ConfigError


class ThrottleConfigError(ConfigError):
    """A ``TokenBucket`` was constructed with an invalid limit.

    Intent: fail loudly at construction on a misconfigured throttle.
    Invariants: ``.field`` names the offending kwarg; ``.value`` is what was
    passed (EH-08). The message carries an actionable hint (EH-09).
    """

    def __init__(self, message: str, *, field: str, value: float) -> None:
        self.field = field
        self.value = value
        super().__init__(message)


class DjangoSettingTypeError(ConfigError):
    """A Django setting bridged to mgf-common has the wrong type.

    Intent: fail loudly when ``settings.py`` holds a non-str where a str|None is
    required. Invariant: ``.received_type`` is the offending type name (EH-08).
    """

    def __init__(self, message: str, *, received_type: str) -> None:
        self.received_type = received_type
        super().__init__(message)
