
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/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-pf2p_tfi*_@epliw=zer)=s$221tgt35uqxio7k2v28lewys&9'

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

ALLOWED_HOSTS = ["refs.rubeya.bi"]
CSRF_TRUSTED_ORIGINS = ["https://refs.rubeya.bi"]


# Application definition

INSTALLED_APPS = [
    # ...
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "refs",
    "django_ckeditor_5",
]

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 = 'rubco.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 = 'rubco.wsgi.application'


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

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",  # or mysql/postgresql
        "NAME": BASE_DIR / "db.sqlite3",
    },
    "audit": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "audit.sqlite3",
    },
}

DATABASE_ROUTERS = ["refs.db_router.AuditRouter"]

# Password validation
# https://docs.djangoproject.com/en/5.0/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',
    },
]


LOGIN_URL = "/login/"
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/login/"

TIME_ZONE = "Africa/Bujumbura"
USE_TZ = True

# Reference format constants

REF_COMPANY = "RU&CO"

# Index reset policy: "monthly", "yearly", or "never"
REF_INDEX_RESET_POLICY = "yearly"


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

STATIC_URL = 'static/'

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static/'),)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'



LOGOUT_REDIRECT_URL = "/login/"


CKEDITOR_5_CONFIGS = {
    "default": {
        "toolbar": [
            "heading", "|",
            "fontFamily",
            "bold", "italic", "underline", "|",
            "bulletedList", "numberedList", "|",
            "alignment", "|",
            "link", "blockQuote", "|",
            "undo", "redo", "|",
            "insertImage"
        ],
        "language": "en",
        "fontFamily": {
            "options": [
                "default",
                "Arial, Helvetica, sans-serif",
                'Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif',
                "Times New Roman, Times, serif",
                "Courier New, Courier, monospace",
                "Georgia, serif",
            ]
        },
        # simpleUpload: CKEditor5 will POST files here and expects JSON { "url": "/media/..." }
        "simpleUpload": {
            "uploadUrl": "/refs/ckeditor_upload/",
            # headers may be added by the widget; leave empty or set custom headers here
            "headers": {}
        },
        # allow resizing unit in px (helps mapping editor sizes to Word)
        "image": {
            "resizeUnit": "px",
            "toolbar": [
                "imageTextAlternative",
                "toggleImageCaption",
                "imageStyle:alignLeft",
                "imageStyle:alignCenter",
                "imageStyle:alignRight",
                "linkImage"
            ]
        },
        "allowedContent": True,
    }
}

