from .base import *

SITE_NAME = "Live"
DEBUG = False
SECURE_SSL_REDIRECT = True

env_path = os.path.join(BASE_DIR, ".env")
environ.Env.read_env(env_path)

INSTALLED_APPS += ["raven.contrib.django.raven_compat"]

DATABASES = {"default": env.db_url("DATABASE_URL")}

ALLOWED_HOSTS = ["www.coombewoodltc.com", "www.coombewoodltc.co.uk"]

TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG

STATIC_ROOT = os.path.join(BASE_DIR, "static_files/")
SECRET_KEY = env.str("SECRET_KEY")

BEE_FREE_ID = env.str("BEE_FREE_ID")
BEE_FREE_SECRET = env.str("BEE_FREE_SECRET")

POS_COOKIE = env.str("POS_COOKIE")

EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
ANYMAIL = env.dict("ANYMAIL")

CARDLESS_ACCESS_TOKEN = env.str("CARDLESS_PRODUCTION_TOKEN")
CARDLESS_ENVIRONMENT = "live"
CARDLESS_WEBHOOK_SECRET = env.str("CARDLESS_WEBHOOK_SECRET")

RAVEN_CONFIG = {"dsn": env.str("RAVEN")}

# https://www.webforefront.com/django/setupdjangologging.html
LOGGING = {
    "version": 1,
    "disable_existing_loggers": True,
    "filters": {
        "require_debug_false": {"()": "django.utils.log.RequireDebugFalse"},
        "require_debug_true": {"()": "django.utils.log.RequireDebugTrue"},
    },
    "formatters": {
        "simple": {"format": "[%(asctime)s] %(levelname)s %(message)s", "datefmt": "%Y-%m-%d %H:%M:%S"},
        "verbose": {
            "format": "[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
            "datefmt": "%Y-%m-%d %H:%M:%S",
        },
    },
    "handlers": {
        "console": {
            "level": "DEBUG",
            "filters": ["require_debug_true"],
            "class": "logging.StreamHandler",
            "formatter": "simple",
        },
        "production_logfile": {
            "level": "INFO",
            "filters": ["require_debug_false"],
            "class": "logging.handlers.RotatingFileHandler",
            "filename": "./logs/django.log",
            "maxBytes": 1024 * 1024 * 10,  # 10MB
            "backupCount": 5,
            "formatter": "simple",
        },
        "sentry": {
            "level": "ERROR",  # To capture more than ERROR, change to WARNING, INFO, etc.
            "filters": ["require_debug_false"],
            "class": "raven.contrib.django.raven_compat.handlers.SentryHandler",
            "tags": {"custom-tag": SITE_NAME},
        },
    },
    "root": {"level": "DEBUG", "handlers": ["console"]},
    "loggers": {
        "members": {"handlers": ["production_logfile", "sentry"]},
        "django": {"handlers": ["console", "sentry"], "propagate": True},
        # stop sentry logging disallowed host
        "django.security.DisallowedHost": {"handlers": ["console"], "propagate": False},
        "django.request": {  # debug logging of things that break requests
            "handlers": ["production_logfile", "sentry"],
            "level": "DEBUG",
            "propagate": True,
        },
    },
    "py.warnings": {"handlers": ["console"]},
}

WAGTAIL_CACHE = True
CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
        "LOCATION": os.path.join(BASE_DIR, "cache"),
        "KEY_PREFIX": "coderedcms",
        "TIMEOUT": 14400,  # in seconds
    }
}
# todo cache and template loaders
