"""EH-09 — actionable-next-step hints are pinned by substring (so they can't rot)."""

from __future__ import annotations

import pytest

from mgf.django._errors import DjangoSettingTypeError, ThrottleConfigError
from mgf.django._settings import _str_or_none
from mgf.django._throttle import TokenBucket


def test_settings_type_error_hint_pinned() -> None:
    with pytest.raises(DjangoSettingTypeError, match="tighten the setting in"):
        _str_or_none(123)  # type: ignore[arg-type]


def test_throttle_capacity_hint_pinned() -> None:
    with pytest.raises(ThrottleConfigError, match="positive integer capacity"):
        TokenBucket(capacity=0, refill_per_second=1.0)


def test_typed_errors_carry_fields() -> None:
    try:
        TokenBucket(capacity=0, refill_per_second=1.0)
    except ThrottleConfigError as e:
        assert e.field == "capacity" and e.value == 0
