"""Shared base models and validators.

Kept for backwards compatibility: earlier versions of this package exposed
:class:`TokenValidation` as the pydantic mixin that validated the API key.
New code should rely on :func:`accuweather_client._http.validate_token`.
"""

from pydantic import BaseModel, field_validator

from accuweather_client._http import (
    VALID_TOKEN_REGEX,  # noqa: F401  (re-export)
    validate_token,
)


class TokenValidation(BaseModel):
    """Pydantic mixin that validates the ``token`` field on construction.

    Attributes:
        token: An AccuWeather API key (20-64 chars).
    """

    token: str

    @field_validator("token")
    @classmethod
    def validate_token(cls, t: str) -> str:
        """Validate that the API token matches AccuWeather's key format.

        The token value is never echoed in the error message, so failures
        are safe to log.
        """
        return validate_token(t)
