"""
Configuración de PRODUCCIÓN — Catálogo Web Dra. Mariela Moreno Autie
====================================================================
"""

from decouple import Csv, config
from .base import *  # noqa: F401,F403

# ============================================================
# DEBUG — SIEMPRE False en producción
# ============================================================
DEBUG = False

# ============================================================
# HOSTS (🔥 FALTABA ESTO)
# ============================================================
ALLOWED_HOSTS = config(
    "ALLOWED_HOSTS",
    default="dramarielaautie.medcatalogo.com,www.dramarielaautie.medcatalogo.com",
    cast=Csv(),
)

# ============================================================
# APPS — Quitar herramientas de desarrollo
# ============================================================
INSTALLED_APPS = [app for app in INSTALLED_APPS if app != "django_extensions"]

# ============================================================
# REST FRAMEWORK — Solo JSON
# ============================================================
REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"] = [
    "rest_framework.renderers.JSONRenderer",
]

# ============================================================
# CACHÉ — DB (cPanel no Redis)
# ============================================================
CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.db.DatabaseCache",
        "LOCATION": "django_cache_table",
    }
}

# ============================================================
# SESIONES
# ============================================================
SESSION_ENGINE = "django.contrib.sessions.backends.db"

# ============================================================
# CELERY — desactivado
# ============================================================
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True

# ============================================================
# TIMEZONE — cPanel MySQL no tiene tablas tz; CONVERT_TZ falla.
# Desactivar USE_TZ para que Django use DATE() directo.
# ============================================================
USE_TZ = False

# ============================================================
# SEGURIDAD
# ============================================================
SECURE_SSL_REDIRECT = config("SECURE_SSL_REDIRECT", default=False, cast=bool)
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

CSRF_TRUSTED_ORIGINS = config(
    "CSRF_TRUSTED_ORIGINS",
    default="https://dramarielaautie.medcatalogo.com,https://www.dramarielaautie.medcatalogo.com",
    cast=Csv(),
)

# ============================================================
# CORS
# ============================================================
CORS_ALLOW_ALL_ORIGINS = False

# ============================================================
# STATIC FILES (🔥 FIX REAL DEL ERROR 500)
# ============================================================
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"

# 👇 ESTO ES CLAVE para que no falle si falta un archivo
WHITENOISE_MANIFEST_STRICT = False

# ============================================================
# LOGGING (sin caracteres raros)
# ============================================================
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "verbose": {
            "format": "[{asctime}] {levelname} {name} {module}.{funcName}:{lineno} - {message}",
            "style": "{",
        },
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "verbose",
        },
    },
    "root": {
        "handlers": ["console"],
        "level": "INFO",
    },
}
