from .base import *  # noqa
from .base import env

# 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="QJoX6YsaOfXnfh6mEjAR7UFX8LoJitQsHOLnNhEJkq4FFED1TefhAk3RQMhgROzk",
)
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
# ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"]
ALLOWED_HOSTS = ["*"]

# 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"
)

# LOGGING
LOGGING['root']['level'] = "DEBUG"
LOGGING['loggers'] = {
    'django.db.backends': {
        'handlers': ['console'],
        'level': 'DEBUG',
        'propagate': False,
    }
}

# django-debug-toolbar
# ------------------------------------------------------------------------------
if env.bool("SHOW_DEBUG_TOOLBAR", default=False):
    # https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
    INSTALLED_APPS += ["debug_toolbar"]  # noqa F405
    # https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
    MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]  # noqa F405
    # https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
    INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"]
    # https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-panels
    DEBUG_TOOLBAR_PANELS = [
        'debug_toolbar.panels.timer.TimerPanel',
        'debug_toolbar.panels.timer.TimerPanel',
        'debug_toolbar.panels.settings.SettingsPanel',
        'debug_toolbar.panels.headers.HeadersPanel',
        'debug_toolbar.panels.request.RequestPanel',
        'debug_toolbar.panels.sql.SQLPanel',
        'debug_toolbar.panels.staticfiles.StaticFilesPanel',
        'debug_toolbar.panels.templates.TemplatesPanel',
        'debug_toolbar.panels.cache.CachePanel',
        'debug_toolbar.panels.signals.SignalsPanel',
        'debug_toolbar.panels.logging.LoggingPanel',
    ]
    # https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
    DEBUG_TOOLBAR_CONFIG = {
        'SHOW_TOOLBAR_CALLBACK': lambda req: True,
        'SHOW_TEMPLATE_CONTEXT': True,
    }

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

# Celery
# ------------------------------------------------------------------------------
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-eager-propagates
CELERY_TASK_EAGER_PROPAGATES = True

CELERY_BROKER_URL = env("CELERY_BROKER_URL")

CELERY_BROKER_TRANSPORT_OPTIONS = {
    # 'sentinels': env.json("REDIS_SENTINELS", default=[]),
    # 'service_name': env("REDIS_SERVICE_NAME", default="lms"),
    # 'db': 0,
    'password': env("REDIS_PASSWORD", default=None),
}

CELERY_BEATLOCK_LOCK_DISABLED = True


# TVM
# ------------------------------------------------------------------------------
TVM_CLIENT_ID = env.int('TVM_CLIENT_ID')
TVM_CLIENT_SECRET = env('TVM_CLIENT_SECRET')


# Blackbox / Passport
# ------------------------------------------------------------------------------
BLACKBOX_NAME = 'Test'

MIDDLEWARE += [
    "lms.contrib.blackbox.middleware.AuthMiddleware",
    "lms.users.middleware.UserPresenceMiddleware",
]


# drf-spectacular
# ------------------------------------------------------------------------------
SWAGGER_ENABLED = True
