"""
Django settings for djangoProject project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path

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

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['DJANGO_SECRET']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False)

HOMOLOGATION = os.getenv('HOMOLOGATION', False)

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'webservices_enedis',
    'proxy',
    'django_admin_generator',
    'rest_framework',
    'django_extensions',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'proxy.middleware_trace_activite.EnregistreurActivite',
]

ROOT_URLCONF = 'webservices_enedis.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates']
        ,
        '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 = 'webservices_enedis.wsgi.application'

WS_ENEDIS_LOGIN = os.environ['WS_ENEDIS_LOGIN']
WS_ENEDIS_CONTRAT_ID = os.environ['WS_ENEDIS_CONTRAT_ID']
WS_ENEDIS_URL = os.environ['WS_ENEDIS_URL']

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": os.environ['PROXY_DB_NAME'],
        "USER": os.environ['PROXY_DB_USER'],
        "PASSWORD": os.environ['PROXY_DB_PASSWORD'],
        "HOST": os.environ['PROXY_DB_HOST'],
        "PORT": os.environ['PROXY_DB_PORT'],
    }
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

IS_DEV_CONTEXT = (os.environ['ENVIRONEMENT_EXECUTION'] == 'dev')

if not IS_DEV_CONTEXT:
    KEY_PRIVATE_CLIENT_CERTIFICATE = os.environ['KEY_PRIVATE_CLIENT_CERTIFICATE']
    BUCKET_NAME = os.environ['BUCKET_NAME']
    KEY_PUBLIC_CLIENT_CERTIFICATE = os.environ['KEY_PUBLIC_CLIENT_CERTIFICATE']

REST_FRAMEWORK = {
    'DEFAULT_THROTTLE_CLASSES': [
        'rest_framework.throttling.ScopedRateThrottle',
    ],
    'DEFAULT_THROTTLE_RATES': {
        'rechercherpointv2': '1/second',
        'rechercherservicessouscritsmesuresv1': '1/second',
        'consultationpointv4': '1/second',
        'consultationmesuresdetailleesv3': '1/second',
        'consultationmesuresv1': '1/second',
        'consultationdonneestechniquescontractuellesv1': '1/second',
        # 'commandetransmissionhistoriquemesuresv1': '1/second',
        'commandecollectepublicationmesuresv3': '1/second',
        'commandearretservicessouscritsmesuresv1': '1/second',
        'commandeaccesservicessouscritsv1': '1/second',
        'commandem023historiquedonneesmesuresfinesv1': '1/second',
        'commandem023informationstechniquesetcontractuellesv1': '1/second',
        'commandem023mesuresfacturantesv1': '1/second',
    }
}