"""
Django settings for sales_management project.

Generated for the Sales Management System.
"""

from pathlib import Path


# ============================================================
# BASE DIRECTORY
# ============================================================

BASE_DIR = Path(__file__).resolve().parent.parent


# ============================================================
# SECURITY
# ============================================================

SECRET_KEY = 'QEi0&*pBF#gJVH8ZTtD3_Y4xTtu)Xro#o^)%+o6Zmy&4*5lPzR'

DEBUG = False

ALLOWED_HOSTS = [
    'hishabbox.sobalex.com',
    'sobalex.com',
    'www.sobalex.com',
    '127.0.0.1',
    'localhost',
]


# ============================================================
# APPLICATIONS
# ============================================================

INSTALLED_APPS = [

    # --------------------------------------------------------
    # Django built-in applications
    # --------------------------------------------------------

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # --------------------------------------------------------
    # Sales Management applications
    # --------------------------------------------------------

    'accounts',
    'inventory',
    'sales',
    'expenses',
    'reports',
    'payroll',
]


# ============================================================
# MIDDLEWARE
# ============================================================

MIDDLEWARE = [

    'django.middleware.security.SecurityMiddleware',

    'whitenoise.middleware.WhiteNoiseMiddleware',

    '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',

    # --------------------------------------------------------
    # Multi-company / Tenant middleware
    # --------------------------------------------------------

    'accounts.middleware.TenantMiddleware',
]


# ============================================================
# URL CONFIGURATION
# ============================================================

ROOT_URLCONF = 'sales_management.urls'


# ============================================================
# TEMPLATES
# ============================================================

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',

                # Branch switcher + branch name labels for every page
                'accounts.context_processors.branch_context',
            ],
        },
    },
]


# ============================================================
# WSGI
# ============================================================

WSGI_APPLICATION = 'sales_management.wsgi.application'


# ============================================================
# DATABASE
# ============================================================

DATABASES = {

    'default': {

        # MySQL
        'ENGINE': 'django.db.backends.mysql',

        # Main database (as created in cPanel > MySQL Databases)
        'NAME': 'sobalex_office_sheet_management',

        # MySQL username (as created in cPanel > MySQL Databases)
        'USER': 'sobalex_Sales',

        # MySQL password
        'PASSWORD': 'yHU(NO]jGUlp',

        # MySQL server - cPanel MySQL runs on the same server, use 'localhost'
        'HOST': 'localhost',

        # MySQL port
        'PORT': '3306',

        'OPTIONS': {

            # Bengali/Unicode support
            'charset': 'utf8mb4',

            # Strict MySQL mode
            'init_command': (
                "SET sql_mode='STRICT_TRANS_TABLES'"
            ),
        },
    },
}


# ============================================================
# DATABASE ROUTER
# ============================================================
#
# This is important for your multi-company system.
#
# The main database:
#
#     sales_management_db
#
# stores platform/company information.
#
# TenantRouter handles tenant/company databases.
#
# ============================================================

DATABASE_ROUTERS = [
    'accounts.db_router.TenantRouter',
]


# ============================================================
# CUSTOM USER MODEL
# ============================================================

AUTH_USER_MODEL = 'accounts.CustomUser'


# ============================================================
# PASSWORD VALIDATION
# ============================================================

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',
    },
]


# ============================================================
# LANGUAGE
# ============================================================

LANGUAGE_CODE = 'en-us'


# ============================================================
# TIME ZONE
# ============================================================

# Bangladesh time
TIME_ZONE = 'Asia/Dhaka'


USE_I18N = True

USE_TZ = True


# ============================================================
# STATIC FILES
# ============================================================

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    BASE_DIR / 'static',
]

STATIC_ROOT = BASE_DIR / 'staticfiles'

STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    },
}


# ============================================================
# MEDIA FILES
# ============================================================

MEDIA_URL = '/media/'

MEDIA_ROOT = BASE_DIR / 'media'


# ============================================================
# LOGIN / LOGOUT
# ============================================================

LOGIN_URL = '/login/'

LOGIN_REDIRECT_URL = '/dashboard/'

LOGOUT_REDIRECT_URL = '/login/'


# ============================================================
# CSRF
# ============================================================

CSRF_TRUSTED_ORIGINS = [
    'https://hishabbox.sobalex.com',
    'https://sobalex.com',
    'https://www.sobalex.com',
    'http://127.0.0.1:8000',
    'http://localhost:8000',
]


# ============================================================
# SESSION
# ============================================================

SESSION_COOKIE_AGE = 60 * 60 * 8

SESSION_EXPIRE_AT_BROWSER_CLOSE = False


# ============================================================
# FILE UPLOAD
# ============================================================

FILE_UPLOAD_MAX_MEMORY_SIZE = 10 * 1024 * 1024

DATA_UPLOAD_MAX_MEMORY_SIZE = 20 * 1024 * 1024


# ============================================================
# DEFAULT PRIMARY KEY
# ============================================================

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'