# ruff: noqa: F403, F405
from .multitenancy import *  # noqa
from .multitenancy import env, INSTALLED_APPS, MIDDLEWARE

# =============================================================================
# CONTENT SECURITY POLICY (CSP)
# Explicitly imported/re-defined here to ensure they are active in local dev
# =============================================================================
CSP_DEFAULT_SRC = ["'self'", "blob:", "data:"]
CSP_SCRIPT_SRC = [
    "'self'",
    "'unsafe-inline'",
    "'unsafe-eval'",
    "https://js.stripe.com",
    "https://connect-js.stripe.com",
    "https://www.googletagmanager.com",
    "https://www.google-analytics.com",
    "https://cdn.jsdelivr.net",  # Required for Swagger UI
    "blob:",  # Required for Stripe
]
CSP_STYLE_SRC = [
    "'self'",
    "'unsafe-inline'",  # Required for Stripe and many UI libraries
    "https://fonts.googleapis.com",
    "https://cdn.jsdelivr.net",  # Required for Swagger UI
]
CSP_IMG_SRC = [
    "'self'",
    "data:",
    "https://*.stripe.com",
    "https://www.google-analytics.com",
    "https://cdn.jsdelivr.net",  # Required for Swagger UI
]
CSP_CONNECT_SRC = [
    "'self'",
    "https://api.stripe.com",
    "https://connect-js.stripe.com",
    "https://www.google-analytics.com",
    "https://stats.g.doubleclick.net",
]
CSP_FRAME_SRC = [
    "'self'",
    "https://js.stripe.com",
    "https://hooks.stripe.com",
    "https://connect-js.stripe.com",
]


# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = env(
    "DJANGO_SECRET_KEY",
    default="JETIHIJaLl2niIyj134Crg2S2dTURSzyXtd02XPicYcjaK5lJb1otLmNHqs6ZVs0",
)
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", ".lvh.me", "lvh.me", "10.0.1.242", "dd59f59c217b.ngrok-free.app"]  # noqa: S104

# CORS and CSRF are configured in base.py with environment variable overrides
# Local development uses the .env file to set DJANGO_CORS_ALLOWED_ORIGINS

# Cookie configuration for cross-subdomain auth in development (lvh.me)
SESSION_COOKIE_DOMAIN = ".lvh.me"
CSRF_COOKIE_DOMAIN = ".lvh.me"

# ngrok configuration for Stripe webhook testing
# Add ngrok URL to CSRF trusted origins for webhook POST requests
CSRF_TRUSTED_ORIGINS = [
    "http://localhost:5173",
    "http://127.0.0.1:5173",
    "http://lvh.me:5173",
    "http://*.lvh.me:5173",
    "http://*.lvh.me:5174",
    "https://dd59f59c217b.ngrok-free.app",
]

# CACHES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
        "LOCATION": "",
    },
}

# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env(
    "DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend",
)

# WhiteNoise
# ------------------------------------------------------------------------------
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
# INSTALLED_APPS = ["whitenoise.runserver_nostatic", *INSTALLED_APPS]


# django-debug-toolbar - REMOVED
# ------------------------------------------------------------------------------
# Debug toolbar removed as this is an API-only setup

# django-extensions
# ------------------------------------------------------------------------------
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
INSTALLED_APPS += ["django_extensions"]
# CELERY
# ------------------------------------------------------------------------------

# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-eager-propagates
CELERY_TASK_EAGER_PROPAGATES = True

# ASGI
# ------------------------------------------------------------------------------
ASGI_APPLICATION = "config.asgi.application"

# LOGGING - Development
# ------------------------------------------------------------------------------
# Extend the base LOGGING configuration with development settings
LOGGING["disable_existing_loggers"] = False
LOGGING["formatters"]["verbose"] = {
    "format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
}
LOGGING["handlers"]["console"]["formatter"] = "verbose"
LOGGING["root"] = {"level": "DEBUG", "handlers": ["console"]}
LOGGING["loggers"] = {
    "watchfiles": {"level": "WARNING"},
    "watchfiles.main": {"level": "WARNING"},
    "watchfiles.watcher": {"level": "WARNING"},
    "watchdog": {"level": "WARNING"},
    "inotify_buffer": {"level": "WARNING"},
}

# Your stuff...
# ------------------------------------------------------------------------------
