"""
Django settings for test_environment project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
import os
from pathlib import Path
from bloomerp.config import BLOOMERP_APPS, BLOOMERP_MIDDLEWARE, BLOOMERP_USER_MODEL
# 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/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-z_3c&9yw1%dgom54h6vjkas=1nubb0vvr8zv@!^jp236xbuwh_"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

X_FRAME_OPTIONS = "SAMEORIGIN"


# Application definition
# ---------------------------------
# START GENERATE
# ---------------------------------
LOGIN_URL = "login"
LOGOUT_REDIRECT_URL = '/'  # Redirect to homepage after logout
# ---------------------------------
# END GENERATE
# ---------------------------------

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

# ---------------------------------
# START REQUIRED BLOOMERP SETTINGS
# ---------------------------------
INSTALLED_APPS += BLOOMERP_APPS

AUTH_USER_MODEL = 'bloomerp.User'

CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"

CRISPY_TEMPLATE_PACK = "bootstrap5"
# ---------------------------------
# END REQUIRED BLOOMERP SETTINGS
# ---------------------------------

# Needs to be explicitly set to allow for large bulk uploads
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240

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

MIDDLEWARE += BLOOMERP_MIDDLEWARE

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


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

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


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

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True

from django.utils.translation import gettext_lazy as _
LANGUAGES = [
    ("en", _("English")),
    ("es", _("Spanish")),
    ("fr", _("French")),
    ("de", _("German")),
    ("it", _("Italian")),
    ("pt", _("Portuguese")),
    ("nl", _("Dutch")),
]

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

STATIC_URL = "static/"

# Absolute filesystem path where uploaded media files will be stored
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# URL that handles the media served from MEDIA_ROOT
MEDIA_URL = '/media/'

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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


# Custom settings for bloomerp

# ---------------------------------
# START GENERATE
BLOOMERP_SETTINGS = {
    "globals" : {
        "organization_name": "My Company",
        "organization_logo": "logo.png",
        "organization_email": "",
    },
    "BASE_URL": "",
    "ROUTERS" : [
        "test_app.views.router"
    ],
    "OPENAI_API_KEY" : "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"
}
# END GENERATE
# ---------------------------------

