"""
Django settings for projects project.

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

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/
"""

from pathlib import Path
import os


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))

IS_PROD = True
# 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 = "django-insecure-c$zvejjh8ezb91!jaji3@0@p%^&tz7e0ml*+7&_mic%nw2-^1q"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False if IS_PROD else True
PORT = None #8069 if IS_PROD else 8000
# DEBUG = False

DAILY_CRON_TOKEN = "az_daily_cron_token_R82zCWvj6orW1wa7ypSSZSjdYxYwfoVDisDXcjKPDKkujkMZza5X3iDtZ8v55u2k"

# if IS_PROD:
#     SECURE_SSL_REDIRECT = True

ALLOWED_HOSTS = ["localhost", "myapp", "myapp:8000","37.187.54.225","vps-69901a1a.vps.ovh.net","137.184.42.13","simulation.ecolux-btp.com","wiki.naturalhealthservices.ca"]

CSRF_TRUSTED_ORIGINS = [
    "https://*localhost",
    "http://*vps-69901a1a.vps.ovh.net:8069",
    "http://*137.184.42.13:8069",
    "https://*simulation.ecolux-btp.com",
    "http://vps-69901a1a.vps.ovh.net",
    "https://simulation.ecolux-btp.com"
    
]
# Application definition

INSTALLED_APPS = [
    "adminlte3",
    "adminlte3_theme",
    
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "sass_processor",
    "app",
    "tinymce",
    "corsheaders",
    "django_recaptcha",
    "userapp"
    # "debug_toolbar",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    # "debug_toolbar.middleware.DebugToolbarMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "django.middleware.common.CommonMiddleware",
    "projects.middleware.loginRedirect",
]

ROOT_URLCONF = "projects.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [str(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",
                "social_django.context_processors.backends",
                "social_django.context_processors.login_redirect",
                "projects.context_processor.gen_data",
            ],
        },
    },
]

WSGI_APPLICATION = "projects.wsgi.application"


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


if not IS_PROD:

    # DATABASES = {
    #     'default': {
    #         'ENGINE': 'django.db.backends.sqlite3',
    #         'NAME': BASE_DIR +'/test.sqlite3'
    #     },
    # }

    # postegres database

    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
        }
    }


    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
else:

    
    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "production.sqlite3"),
        }
    }
    DEBUG = False  # overwrite debug to false
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


# 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 = "fr"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


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


STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "productionfiles")
STATICFILES_DIRS = [os.path.join(BASE_DIR, "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'


STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "sass_processor.finders.CssFinder",
]

# Django Sass
SASS_PROCESSOR_ROOT = os.path.join(BASE_DIR, "static")

# Media files configuration
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Utiliser toujours le stockage local (plus de Cloudinary)
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"


# AUTHENTICATION_BACKENDS = (
#     "django.contrib.auth.backends.ModelBackend",
#     "social_core.backends.google.GoogleOAuth2",
# )


LOGIN_REDIRECT_URL = "/"
LOGIN_ERROR_URL = "/auth/to_login"


LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
        },
    },
    "root": {
        "handlers": ["console"],
        "level": "DEBUG",
    },
}


SOCIAL_AUTH_JSONFIELD_ENABLED = True

CORS_ALLOWED_ORIGINS = [ "http://localhost:8000","http://vps-69901a1a.vps.ovh.net:8069","http://137.184.42.13:8069","http://vps-69901a1a.vps.ovh.net","https://simulation.ecolux-btp.com"]


# RECAPTCHA_PUBLIC_KEY = "_"
# RECAPTCHA_PRIVATE_KEY = "_"


# for test 
RECAPTCHA_PUBLIC_KEY = "6Lfz2fgrAAAAADw3PGicdhZRAYfYobFO6IB9uuaR"
RECAPTCHA_PRIVATE_KEY = "6Lfz2fgrAAAAAJPEww9AdRHG8Fbv80v8FWmzFgjI"

# RECAPTCHA_PUBLIC_KEY = "6Lc7KQMrAAAAALF1C2dcDmAB9bei1FxNkFyfM1Wx"
# RECAPTCHA_PRIVATE_KEY = "6Lc7KQMrAAAAANvLuEU5gekT1EcZPxn59PC4f6mF"



# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
# EMAIL_HOST = "smtp-relay.brevo.com"
# EMAIL_USE_TLS = False
# EMAIL_PORT = 587
# EMAIL_HOST_USER = "_"
# EMAIL_HOST_PASSWORD = "_"
# DEFAULT_FROM_EMAIL = "AZ <no-reply@test.com>"

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp-relay.brevo.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = '86f2e9002@smtp-brevo.com'
EMAIL_HOST_PASSWORD = 'xsmtpsib-dcb239a137dc4587d702676d680a3a66ae6bc2db472a22f13ef8d99bfa490ea8-9M2HB7IAqQ6YNsvf'
DEFAULT_FROM_EMAIL = 'UP2PAY <no-reply@upgroup-pay.com>'

# Configuration TinyMCE
TINYMCE_DEFAULT_CONFIG = {
    'height': 500,
    'width': '100%',
    'cleanup_on_startup': True,
    'custom_undo_redo_levels': 20,
    'selector': 'textarea',
    'theme': 'silver',
    'plugins': '''
        textcolor save link image media preview codesample contextmenu
        table code lists fullscreen  insertdatetime  nonbreaking
        contextmenu directionality searchreplace wordcount visualblocks
        visualchars code fullscreen autolink lists  charmap print  hr
        anchor pagebreak
    ''',
    'toolbar1': '''
        fullscreen preview bold italic underline | fontselect,
        fontsizeselect  | forecolor backcolor | alignleft alignright |
        aligncenter alignjustify | indent outdent | bullist numlist table |
        | link image media | codesample |
    ''',
    'toolbar2': '''
        visualblocks visualchars |
        charmap hr pagebreak nonbreaking anchor |  code |
    ''',
    'contextmenu': 'formats | link image',
    'menubar': True,
    'statusbar': True,
    'content_css': '/static/admin/css/tinymce_content.css',
    'language': 'fr_FR',
    'image_title': True,
    'automatic_uploads': True,
    'file_picker_types': 'image',
    'images_upload_url': '/admin/upload_image/',
    'relative_urls': False,
}
