"""
Django settings for lottery project.

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

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

from pathlib import Path
import os
from dotenv import load_dotenv

load_dotenv()
# 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 = os.getenv('DJANGO_SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DJANGO_DEBUG')

ALLOWED_HOSTS = os.getenv('DJANGO_ALLOWED_HOSTS', '').split(',') if os.getenv('DJANGO_ALLOWED_HOSTS') else ['localhost', '127.0.0.1']


# Application definition

INSTALLED_APPS = [
    'jazzmin',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'webapp',
    'draw',
    'bot',

]

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 = 'lottery.urls'

import os


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(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 = 'lottery.wsgi.application'


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

DB_ENGINE = os.getenv('DJANGO_DB_ENGINE', 'sqlite').lower()

if DB_ENGINE == 'mariadb' or DB_ENGINE == 'mysql':
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',  # или 'django.db.backends.mysql' для MariaDB
            'NAME': os.getenv('DJANGO_DB_NAME', 'lottery'),
            'USER': os.getenv('DJANGO_DB_USER', 'your_username'),
            'PASSWORD': os.getenv('DJANGO_DB_PASSWORD', 'your_password'),
            'HOST': os.getenv('DJANGO_DB_HOST', 'localhost'),
            'PORT': os.getenv('DJANGO_DB_PORT', '3306'),
            'OPTIONS': {
                'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
            },
        }
    }
else:  # по умолчанию SQLite
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / os.getenv('DJANGO_DB_NAME', 'db.sqlite3'),
        }
    }

CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'


# 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 = 'ru-RU'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / "static",]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


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



JAZZMIN_SETTINGS = {
    # Общие настройки
    "site_title": "LuckyTicket",
    "site_header": "Lucky Ticket",
    "site_brand": "EasyPlay",
    "welcome_sign": "Добро пожаловать в аLuckyTicket",
    "copyright": "© 2025 LuckyTicket",

    # Верхнее меню
    "topmenu_links": [
        {"name": "Домой", "url": "admin:index", "permissions": ["auth.view_user"]},
        {"app": "auth", "model": "user"},
        {"app": "draw", "label": "Розыгрыши"},
    ],
    
    # Меню пользователя (справа сверху)
    "usermenu_links": [
        {"name": "Мой профиль", "url": "admin:password_change", "icon": "fas fa-user"},
        {"model": "auth.user"},
    ],
    
    # Настройка сайдбара
    "show_sidebar": True,
    "navigation_expanded": False,  # развёрнутый сайдбар по умолчанию
    "sidebar_nav_styles": {
        # Пример: добавляем отступ для вложенных элементов
        "default": {
            "indent": 20,  # отступ в пикселях
        }
    },
    
    # Иконки для моделей
    "icons": {
        "bot" : "fa-solid fa-robot",
        "bot.BotConfig" : "fa-solid fa-wrench",
        "bot.BotMessage" : "fas fa-envelope",
        "bot.BotEventMessageConfig" : "fa-solid fa-screwdriver-wrench",
        "bot.WelcomeMessage" : "fa-solid fa-message",
        "auth": "fas fa-user",
        "auth.user": "fas fa-user",
        "auth.Group": "fas fa-users",
        "draw" : "fa-solid fa-dice",
        "draw.lottery": "fas fa-ticket-alt",
        "draw.prize": "fas fa-gift",
        "draw.lotteryparticipant": "fas fa-user-check",
        "draw.drawresult": "fas fa-trophy",
        "webapp" : "fas fa-globe",
        "webapp.client": "fas fa-address-card",
        "webapp.invoice": "fas fa-file-invoice-dollar",
        "webapp.BindingRequest" : "fas fa-link",
    },
    
    # Формат представления форм (если нужно)
    "changeform_format": "horizontal_tabs",
    
    # Дополнительные настройки (можно добавить свои CSS/JS файлы)
    "custom_css": "css/custom.css",
    "custom_js": None,
    "show_ui_builder": False,
}