"""
Django development settings for the cof project.
The settings that are not listed here are imported from .common
"""
import os

from .common import *  # NOQA
from .common import (
    AUTHENTICATION_BACKENDS,
    BASE_DIR,
    INSTALLED_APPS,
    MIDDLEWARE,
    TEMPLATES,
    import_secret,
)

# ---
# COF-specific secrets
# ---

RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY")
RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY")
KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN")

# ---
# COF-only Django settings
# ---

ALLOWED_HOSTS = ["cof.ens.fr", "www.cof.ens.fr", "dev.cof.ens.fr"]

INSTALLED_APPS = (
    [
        "gestioncof",
        # Must be before django admin
        # https://github.com/infoportugal/wagtail-modeltranslation/issues/193
        "wagtail_modeltranslation",
        "wagtail_modeltranslation.makemigrations",
        "wagtail_modeltranslation.migrate",
        "modeltranslation",
    ]
    + INSTALLED_APPS
    + [
        "bda",
        "petitscours",
        "captcha",
        "kfet",
        "kfet.open",
        "channels",
        "custommail",
        "djconfig",
        "wagtail.contrib.forms",
        "wagtail.contrib.redirects",
        "wagtail.embeds",
        "wagtail.sites",
        "wagtail.users",
        "wagtail.snippets",
        "wagtail.documents",
        "wagtail.images",
        "wagtail.search",
        "wagtail.admin",
        "wagtail.core",
        "wagtail.contrib.modeladmin",
        "wagtail.contrib.routable_page",
        "wagtailmenus",
        "modelcluster",
        "taggit",
        "kfet.auth",
        "kfet.cms",
        "gestioncof.cms",
        "django_js_reverse",
    ]
)

MIDDLEWARE = (
    ["corsheaders.middleware.CorsMiddleware"]
    + MIDDLEWARE
    + [
        "djconfig.middleware.DjConfigMiddleware",
        "wagtail.core.middleware.SiteMiddleware",
        "wagtail.contrib.redirects.middleware.RedirectMiddleware",
    ]
)

TEMPLATES[0]["OPTIONS"]["context_processors"] += [
    "wagtailmenus.context_processors.wagtailmenus",
    "djconfig.context_processors.config",
    "gestioncof.shared.context_processor",
    "kfet.auth.context_processors.temporary_auth",
    "kfet.context_processors.config",
]

STATIC_ROOT = os.path.join(
    os.path.dirname(os.path.dirname(BASE_DIR)), "public", "gestion", "static"
)

STATIC_URL = "/gestion/static/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media")
MEDIA_URL = "/gestion/media/"

CORS_ORIGIN_WHITELIST = ("bda.ens.fr", "www.bda.ens.fr" "cof.ens.fr", "www.cof.ens.fr")


# ---
# Auth-related stuff
# ---

AUTHENTICATION_BACKENDS += [
    "gestioncof.shared.COFCASBackend",
    "kfet.auth.backends.GenericBackend",
]

LOGIN_URL = "cof-login"
LOGIN_REDIRECT_URL = "home"


# ---
# reCAPTCHA settings
# https://github.com/praekelt/django-recaptcha
#
# Default settings authorize reCAPTCHA usage for local developement.
# Public and private keys are appended in the 'prod' module settings.
# ---

NOCAPTCHA = True
RECAPTCHA_USE_SSL = True


# ---
# Wagtail settings
# ---

WAGTAIL_SITE_NAME = "GestioCOF"
WAGTAIL_ENABLE_UPDATE_CHECK = False
TAGGIT_CASE_INSENSITIVE = True


# ---
# Django-js-reverse settings
# ---

JS_REVERSE_JS_VAR_NAME = "django_urls"
# Quand on aura namespace les urls...
# JS_REVERSE_INCLUDE_ONLY_NAMESPACES = ['k-fet']


# ---
# Mail config
# ---

MAIL_DATA = {
    "petits_cours": {
        "FROM": "Le COF <cof@ens.fr>",
        "BCC": "archivescof@gmail.com",
        "REPLYTO": "cof@ens.fr",
    },
    "rappels": {"FROM": "Le BdA <bda@ens.fr>", "REPLYTO": "Le BdA <bda@ens.fr>"},
    "revente": {
        "FROM": "BdA-Revente <bda-revente@ens.fr>",
        "REPLYTO": "BdA-Revente <bda-revente@ens.fr>",
    },
}
