"""
mizan.jwt - JWT authentication for server functions.

Provides:
- Server functions for obtaining/refreshing JWT tokens
- JWT authentication utilities for validating tokens

Server Functions:
- jwt_obtain: Convert authenticated session to JWT tokens
- jwt_refresh: Refresh tokens using a refresh token

Usage in apps.py or urls.py (to register the functions):
    import mizan.jwt.functions  # noqa: F401

Note: This module is purpose-built for mizan server functions.
For Django Ninja API authentication, use mizan.jwt.security directly.
"""

# Server functions (import to register with @client decorator)
from .functions import jwt_obtain, jwt_refresh

# Token utilities
from .tokens import (
    create_token_pair,
    create_access_token,
    create_refresh_token,
    decode_token,
    refresh_tokens,
    TokenPair,
    TokenPayload,
    JWTUser,
)

# Settings
from .settings import get_settings, JWTSettings

# Security (Ninja API auth) - lazy import to avoid triggering
# django-ninja's settings access at module load time.
# Use: from mizan.jwt.security import jwt_auth


def __getattr__(name):
    if name in ("JWTAuth", "jwt_auth"):
        from .security import JWTAuth, jwt_auth

        globals()["JWTAuth"] = JWTAuth
        globals()["jwt_auth"] = jwt_auth
        return globals()[name]
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__all__ = [
    # Server functions
    "jwt_obtain",
    "jwt_refresh",
    # Token utilities
    "create_token_pair",
    "create_access_token",
    "create_refresh_token",
    "decode_token",
    "refresh_tokens",
    "TokenPair",
    "TokenPayload",
    "JWTUser",
    # Settings
    "get_settings",
    "JWTSettings",
    # Security (lazy)
    "JWTAuth",
    "jwt_auth",
]
