import os

from .base import *

DEBUG = True

# The dev Caddy TLS terminator (https://iilmp.local) proxies to this runserver over
# HTTP and forwards X-Forwarded-Proto. Honour it so Django reports request.is_secure()
# and emits https:// URLs in the OIDC discovery document (Moodle requires https).
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

STORAGES = {
    **STORAGES,
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}

INSTALLED_APPS += ["django_browser_reload"]
MIDDLEWARE += ["django_browser_reload.middleware.BrowserReloadMiddleware"]

# Console by default; if EMAIL_HOST is set (e.g. in .env), use real SMTP like production.
if os.getenv("EMAIL_HOST", "").strip():
    EMAIL_BACKEND = os.getenv("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
    EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
    EMAIL_PORT = int(os.getenv("EMAIL_PORT", "587"))
    EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", "True").lower() == "true"
    EMAIL_USE_SSL = os.getenv("EMAIL_USE_SSL", "False").lower() == "true"
    EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
    EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
else:
    EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

# Avoid Redis dependency for sessions during local runs without cache.
SESSION_ENGINE = "django.contrib.sessions.backends.db"
