"""
Internal (non-operator-tunable) constants for the Discord audit module.

Operator-tunable settings live in ``app_settings.py`` and are read via
``clean_setting``; everything in this module is fixed at code-time and
should not be overridable from ``local.py``. Splitting the two keeps
the operator-facing contract clean: anything imported from
``app_settings`` is something a deployer can change.
"""

from __future__ import annotations

from typing import Final

from .permissions import APP_LABEL

# Discord ``GET /guilds/{id}/members`` upper bound per call.
PAGE_SIZE: Final[int] = 1000

# Hard cap on pagination iterations for ``guild_members``. Multiplied
# by ``PAGE_SIZE`` this allows up to 1M members per audit before the
# pager terminates defensively — well above any realistic alliance
# size while still protecting against an upstream that ignores the
# ``after`` cursor and returns the same page indefinitely.
MAX_GUILD_MEMBER_PAGES: Final[int] = 1000

# HTTP methods accepted by ``AuditedDiscordClient._api_request``.
# ``getattr(requests, method)`` previously checked ``hasattr`` only,
# which would let through ``requests.session`` / ``requests.utils`` /
# ``requests.request`` if a future caller passed a typo. The set
# below mirrors what the upstream Discord routes actually use.
ALLOWED_HTTP_METHODS: Final[frozenset[str]] = frozenset(
    {"get", "post", "patch", "put", "delete"}
)

# Dotted path to the middleware that captures the per-request actor for
# ``ConfigChangeLog`` attribution. Built from ``APP_LABEL`` so a future
# package rename does not silently leave a stale reference here while
# the validator at startup keeps emitting ``ImproperlyConfigured``
# pointing to the wrong path.
MIDDLEWARE_PATH: Final[str] = f"{APP_LABEL}.current_user.CurrentUserMiddleware"

# Django app label for AA's Discord service module. Used by the
# startup validator that enforces INSTALLED_APPS ordering; centralised
# here so tests / docs can reference a single source of truth.
DISCORD_SERVICE_APP_LABEL: Final[str] = "allianceauth.services.modules.discord"
