"""
Django settings for core project. 
"""

from pathlib import Path
from decouple import config, Csv
from django.utils.translation import gettext_lazy as _  


# 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.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config("SECRET_KEY", default="for test is empty", cast=str) 

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config("DEBUG", default=False, cast=bool)

ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="*" , cast=Csv()) 

SITE_ID = config("SITE_ID", default=1, cast=int)

# Application definition

INSTALLED_APPS = [
    # Django Apps
    "django.contrib.admin",
    "django.contrib.auth",            # Core authentication framework and its default models.
    "django.contrib.contenttypes",    # Django content type system (allows permissions to be associated with models).
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.sites",
    # Installed Apps

    # Our Apps
    "apps.dashboard",
    "apps.accounts"
]

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",
]

ROOT_URLCONF = "core.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 = "core.wsgi.application"


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


DATABASES = { 
    "default": {
        "ENGINE"   : config("SQL_ENGINE", default="django.db.backends.sqlite3", cast=str),
        "NAME"     : config("SQL_DATABASE", default=(BASE_DIR/"db.sqlite3"), cast=str),
        "USER"     : config("SQL_USER", default="user", cast=str),
        "PASSWORD" : config("SQL_PASSWORD", default="password", cast=str),
        "HOST"     : config("SQL_HOST", default="localhost", cast=str),
        "PORT"     : config("SQL_PORT", default="5432", cast=int),
    }, 
}


# Password validation
# https://docs.djangoproject.com/en/3.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.0/topics/i18n/

LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"

USE_I18N = True
USE_L10N = True
USE_TZ = True

LANGUAGE_CODE = "en"
LANGUAGES = [
    ("ar", _("Arabic")),
    ("en", _("English")),
    ("fr", _("French")),
]

LOCALE_PATHS = (
    (BASE_DIR/"locale"),
)

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

STATIC_URL       = "/static/"
STATIC_ROOT      = (BASE_DIR/"staticfiles")
STATICFILES_DIRS = [(BASE_DIR/"static"),]

MEDIA_URL        = "/media/"
MEDIA_ROOT       = (BASE_DIR/"media")

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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"