"""Platform-wide constants shared across all apps.

Rules
-----
* No imports from ``simorgh.apps.*``
* No mutable collections (use tuples, not lists, for sequences)
* Group by logical domain; add a comment before each section

Usage::

    from simorgh.shared.constants import MAX_UPLOAD_BYTES, SUPPORTED_LOCALES
"""
from __future__ import annotations

__all__ = [
    # File / storage
    "MAX_UPLOAD_BYTES",
    "MAX_UPLOAD_MB",
    "ALLOWED_IMAGE_MIMES",
    "ALLOWED_DOCUMENT_MIMES",
    "ALLOWED_ARCHIVE_MIMES",
    # Pagination
    "DEFAULT_PAGE_SIZE",
    "MAX_PAGE_SIZE",
    # Localisation
    "SUPPORTED_LOCALES",
    "SUPPORTED_CALENDARS",
    "DEFAULT_LOCALE",
    "DEFAULT_CALENDAR",
    "RTL_LOCALES",
    # Auth / security
    "PASSWORD_MIN_LENGTH",
    "SESSION_COOKIE_AGE_SECONDS",
    "ACCESS_TOKEN_LIFETIME_SECONDS",
    "REFRESH_TOKEN_LIFETIME_SECONDS",
    "OTP_EXPIRY_SECONDS",
    "OTP_MAX_ATTEMPTS",
    # Workflow / status
    "STATUS_ACTIVE",
    "STATUS_INACTIVE",
    "STATUS_DRAFT",
    "STATUS_PUBLISHED",
    "STATUS_ARCHIVED",
    "STATUS_DELETED",
    "STATUS_CHOICES",
    # Notifications
    "NOTIFICATION_CHANNEL_INBOX",
    "NOTIFICATION_CHANNEL_EMAIL",
    "NOTIFICATION_CHANNEL_SMS",
    "NOTIFICATION_CHANNEL_WEBSOCKET",
    # Tenancy
    "TENANT_SLUG_MAX_LENGTH",
    "TENANT_NAME_MAX_LENGTH",
    # Audit
    "AUDIT_ACTION_CREATE",
    "AUDIT_ACTION_UPDATE",
    "AUDIT_ACTION_DELETE",
    "AUDIT_ACTION_VIEW",
    "AUDIT_ACTION_LOGIN",
    "AUDIT_ACTION_LOGOUT",
    # Misc
    "UUID_ZERO",
]

# ---------------------------------------------------------------------------
# File / storage
# ---------------------------------------------------------------------------

MAX_UPLOAD_MB: int = 50
MAX_UPLOAD_BYTES: int = MAX_UPLOAD_MB * 1024 * 1024  # 52_428_800

ALLOWED_IMAGE_MIMES: tuple[str, ...] = (
    "image/jpeg",
    "image/png",
    "image/gif",
    "image/webp",
    "image/svg+xml",
    "image/tiff",
)

ALLOWED_DOCUMENT_MIMES: tuple[str, ...] = (
    "application/pdf",
    "application/msword",
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "application/vnd.ms-excel",
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "application/vnd.ms-powerpoint",
    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    "text/plain",
    "text/csv",
    "application/rtf",
    "application/vnd.oasis.opendocument.text",
    "application/vnd.oasis.opendocument.spreadsheet",
)

ALLOWED_ARCHIVE_MIMES: tuple[str, ...] = (
    "application/zip",
    "application/x-rar-compressed",
    "application/x-tar",
    "application/gzip",
    "application/x-7z-compressed",
)

# ---------------------------------------------------------------------------
# Pagination
# ---------------------------------------------------------------------------

DEFAULT_PAGE_SIZE: int = 25
MAX_PAGE_SIZE: int = 200

# ---------------------------------------------------------------------------
# Localisation
# ---------------------------------------------------------------------------

SUPPORTED_LOCALES: tuple[str, ...] = ("fa", "ar", "en", "tr", "ps")
DEFAULT_LOCALE: str = "fa"

SUPPORTED_CALENDARS: tuple[str, ...] = ("gregorian", "jalali", "hijri")
DEFAULT_CALENDAR: str = "gregorian"

# Locales that use right-to-left text direction
RTL_LOCALES: frozenset[str] = frozenset({"fa", "ar", "he", "ur", "ps"})

# ---------------------------------------------------------------------------
# Auth / security
# ---------------------------------------------------------------------------

PASSWORD_MIN_LENGTH: int = 8

# Django session cookie age (14 days)
SESSION_COOKIE_AGE_SECONDS: int = 14 * 24 * 60 * 60

# JWT / token lifetimes
ACCESS_TOKEN_LIFETIME_SECONDS: int = 15 * 60          # 15 minutes
REFRESH_TOKEN_LIFETIME_SECONDS: int = 7 * 24 * 60 * 60  # 7 days

# OTP (one-time password)
OTP_EXPIRY_SECONDS: int = 5 * 60  # 5 minutes
OTP_MAX_ATTEMPTS: int = 3

# ---------------------------------------------------------------------------
# Generic status codes (used by multiple apps)
# ---------------------------------------------------------------------------

STATUS_ACTIVE: str = "active"
STATUS_INACTIVE: str = "inactive"
STATUS_DRAFT: str = "draft"
STATUS_PUBLISHED: str = "published"
STATUS_ARCHIVED: str = "archived"
STATUS_DELETED: str = "deleted"

STATUS_CHOICES: tuple[tuple[str, str], ...] = (
    (STATUS_ACTIVE, "Active"),
    (STATUS_INACTIVE, "Inactive"),
    (STATUS_DRAFT, "Draft"),
    (STATUS_PUBLISHED, "Published"),
    (STATUS_ARCHIVED, "Archived"),
    (STATUS_DELETED, "Deleted"),
)

# ---------------------------------------------------------------------------
# Notifications
# ---------------------------------------------------------------------------

NOTIFICATION_CHANNEL_INBOX: str = "inbox"
NOTIFICATION_CHANNEL_EMAIL: str = "email"
NOTIFICATION_CHANNEL_SMS: str = "sms"
NOTIFICATION_CHANNEL_WEBSOCKET: str = "websocket"

# ---------------------------------------------------------------------------
# Tenancy
# ---------------------------------------------------------------------------

TENANT_SLUG_MAX_LENGTH: int = 63   # RFC 1123 hostname label limit
TENANT_NAME_MAX_LENGTH: int = 255

# ---------------------------------------------------------------------------
# Audit actions
# ---------------------------------------------------------------------------

AUDIT_ACTION_CREATE: str = "create"
AUDIT_ACTION_UPDATE: str = "update"
AUDIT_ACTION_DELETE: str = "delete"
AUDIT_ACTION_VIEW: str = "view"
AUDIT_ACTION_LOGIN: str = "login"
AUDIT_ACTION_LOGOUT: str = "logout"

# ---------------------------------------------------------------------------
# Misc
# ---------------------------------------------------------------------------

UUID_ZERO: str = "00000000-0000-0000-0000-000000000000"
