"""
Django settings for django_for_startups project.

Generated by 'django-admin startproject' using Django 3.1.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import datetime
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Application definition

DEBUG = False

ALLOWED_HOSTS = []


INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_extensions",
    "rest_framework",
    "app",
]

MIDDLEWARE = [
    "django_customizations.core_django_customizations.CustomSecurityHeaders",
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

REST_FRAMEWORK = {
    "DEFAULT_PERMISSION_CLASS": ("rest_framework.permissions.IsAuthenticated",),
    'DEFAULT_AUTHENTICATION_CLASSES': ( 'django_customizations.drf_jwt_customizations.CustomJSONWebTokenAuthentication',),
    "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
    "DEFAULT_THROTTLE_CLASSES": (
        "rest_framework.throttling.AnonRateThrottle",
        'django_customizations.drf_customizations.BurstRateThrottle',
        'django_customizations.drf_customizations.SustainedRateThrottle',
    ),
    "DEFAULT_THROTTLE_RATES": {
        "anon": "5000/day",
        "burst": "200/min",
        "sustained": "5000/day",
    },
    "TEST_REQUEST_DEFAULT_FORMAT": "json",
}

AUTHENTICATION_BACKENDS = ('django_customizations.core_django_customizations.CaseInsensitiveUserAuth',)


ROOT_URLCONF = "urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    },
]

WSGI_APPLICATION = "wsgi.application"

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        },
    }
}

# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Must be changed for NGINX or Apache in production, c.f.
# http://stackoverflow.com/questions/7620307/how-do-i-serve-css-to-django-in-development
STATIC_ROOT = ""
AUTH_USER_MODEL = "app.User"

# Relative URL to the static assets folder inside each app
STATIC_URL = "/static/"
MEDIA_ROOT = ""
STATICFILES_DIRS = []

# Security
X_FRAME_OPTIONS = "DENY"
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
CSRF_COOKIE_HTTPONLY = True

CORS_ALLOW_ALL_ORIGINS = False
CORS_PREFLIGHT_MAX_AGE = 36000
CORS_ALLOW_HEADERS = (
    "x-requested-with",
    "content-type",
    "accept",
    "accept-encoding" "origin",
    "authorization",
    "x-csrftoken",
    "accept-encoding",
)


PASSWORD_HASHERS = [
    "django.contrib.auth.hashers.Argon2PasswordHasher",
    "django.contrib.auth.hashers.PBKDF2PasswordHasher",
    "django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
    "django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
    "django.contrib.auth.hashers.BCryptPasswordHasher",
]

MIN_PASSWORD_LENGTH = 8
AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
        "OPTIONS": {
            "min_length": MIN_PASSWORD_LENGTH,
        },
    },
]

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': datetime.timedelta(days=90),
    'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=365),
    'USER_ID_FIELD': 'nfkc_username',
    'USER_ID_CLAIM': 'username',
    'AUTH_HEADER_TYPES': 'JWT',
    'ALGORITHM': 'HS256'
 }
