"""
Django settings for touchh project.

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

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()
import os
from pprint import pprint
from app_settings.app_settings import load_database_settings


# 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-l_8uu8#p*^zf)9zry80)6u+!+2g1a4tg!wx7@^!uw(+^axyh&h'

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

ALLOWED_HOSTS = ['0.0.0.0', '192.168.219.140', '127.0.0.1', 'localhost', '192.168.219.114', '8f6e-182-226-158-253.ngrok-free.app', '*.ngrok-free.app']

CSRF_TRUSTED_ORIGINS = [
    'https://8f6e-182-226-158-253.ngrok-free.app',
    'https://*.ngrok-free.app',  # Это подойдет для любых URL, связанных с ngrok
]

# Application definition

INSTALLED_APPS = [
    'jazzmin',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bot',
    'pms_integration',
    'hotels',
    'users',
    'scheduler',
    'antifroud',
    'health_check',
    'health_check.db',
    'health_check.cache',
    'app_settings',

]

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 = 'touchh.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 = 'touchh.wsgi.application'
GEOIP_PATH = os.path.join(BASE_DIR, 'geoip')

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.getenv('DB_NAME', default='touchh'),  # Имя базы данных
        'USER': os.getenv('DB_ROOT_USER', default='touchh'),  # Имя пользователя базы данных
        'PASSWORD': os.getenv('DB_PASSWORD', default='touchh'),  # Пароль пользователя
        'HOST': os.getenv('DB_HOST', default='db'),  # Хост (по умолчанию localhost)
        'PORT': os.getenv('DB_PORT', default=3306),  # Порт (по умолчанию 3306)
        'ATOMIC_REQUESTS': True,

    },
}
# load_database_settings(DATABASES)

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

# settings.py

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': os.getenv("LOG_LEVEL"),
            'class': 'logging.FileHandler',
            'filename': 'var/log/import_hotels.log',  # Лог будет записываться в этот файл
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': os.getenv("LOG_LEVEL"),
            'propagate': True,
        },
        'antifroud': {
            'handlers': ['file'],
            'level': os.getenv("LOG_LEVEL"),
            'propagate': True,
        },
    },
}


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'Europe/Moscow'

USE_TZ = True

USE_I18N = True

USE_L10N = True



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

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']


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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


JAZZMIN_SETTINGS = {
    "use_bootstrap5": True,
    "custom_css": "admin/custom.css",
    "site_title": "TOUCHH Hotel Management",
    "site_header": "TOUCHH Hotel Manager Admin",
    "site_brand": "TOUCHH",
    "welcome_sign": "Welcome to TOUCHH Hotel Management System",
    "show_sidebar": True,
    "navigation_expanded": False,
    "hide_models": ["auth", "guests"],
    "order_with_respect_to": ["users", "hotels"],
    "site_logo": None,  # Путь к логотипу, например "static/images/logo.png"
    "site_logo_classes": "img-circle",  # Классы CSS для логотипа
    "site_icon": None,  # Иконка сайта (favicon), например "static/images/favicon.ico"
    "welcome_sign": "Welcome to Touchh Admin",  # Приветствие на странице входа
    "copyright": "Touchh",  # Кастомный текст в футере
    "menu": [
        {
            "app": "hotels",
            "label": "Управление отелями",
            "icon": "fas fa-hotel",
            "models": [
                {"model": "hotels.hotel", "label": "Отели"},
                {"model": "hotels.room", "label": "Номера", "css_classes": "ml-6"},
                {"model": "hotels.reservation", "label": "Бронирования", "css_classes": "ml-6"},
                {"model": "hotels.userhotel", "label": "Пользователи отеля", "css_classes": "ml-6"},
            ],
        },

    ],
    "icons": {
        # Приложения
        "hotels": "fas fa-hotel",
        "scheduler": "fas fa-clock",
        "pms_integration": "fas fa-sync",
        "antifraud": "fas fa-shield-alt",
        "app_settings": "fas fa-wrench",

        # Модели
        "hotels.reservation": "fas fa-calendar-check",  # Бронирования
        "hotels.userhotel": "fas fa-user-shield",  # Пользователи отеля
        "app_settings.telegramsettings": "fab fa-telegram",  # Настройки Telegram
        "app_settings.emailsettings": "fas fa-envelope",  # Настройки Email
        "app_settings.localdatabase": "fas fa-database",  # Локальная база данных
        "app_settings.globalhotelsettings": "fas fa-tools",  # Глобальные настройки отеля
        "app_settings.globalsystemsettings": "fas fa-cogs",  # Глобальные системные настройки
        "antifraud.externaldbsettings": "fas fa-server",  # Подключение к внешним базам данных
        "antifraud.roomdiscrepancy": "fas fa-exclamation-circle",  # Несоответствия в комнатах
        "scheduler.scheduledtask": "fas fa-tasks",  # Запланированные задачи
        "antifraud.violationlog": "fas fa-ban",  # Журнал нарушений
        "hotels.importedhotel": "fas fa-download",  # Импортированные отели
        "hotels.synclog": "fas fa-sync-alt",  # Журнал синхронизации

            "auth": "fas fa-users-cog",
            "users": "fas fa-user-circle",
            "hotels": "fas fa-hotel",
            "hotels.hotel": "fas fa-hotel",
            "hotels.room":"fas fa-bed",
            "hotels.reservation":"fas fa-calendar-week",
            "hotels.userhotel":"fas fa-user-shield",
            "app_settings": "fas fa-wrench",
            "app_settings.telegramsettings":"fab fa-telegram",
            "app_settings.emailsettings":"fab fa-at",
            "app_settings.localdatabase":"fas fa-database",
            "app_settings.globalhotelsettings":"fas fa-hammer",
            "app_settings.globalsystemsettings":"fas fa-cogs",
            "scheduler": "fas fa-clock",
            "pms_integration": "fas fa-sync",
            "antifroud": "fas fa-shield-alt",
            "antifroud.externaldbsettings": "fas fa-database",
            "antifroud.roomdiscrepancy": "fas fa-user-secret",
            "antifroud.violationlog": "fas fa-ban",
            "antifroud.importedhotel": "fas fa-download",
            "antifroud.synclog": "fas fa-sync-alt",
            "antifroud.useractivitylog": "fas fa-qrcode",
            },



    "theme": "sandstone",
    "dark_mode_theme": "darkly",
    "footer": {
        "copyright": "SmartSolTech.kr © 2024",
        "version": False,
    },
    "dashboard_links": [
        {"name": "Google", "url": "https://touchh.com", "new_window": True},
        {"name": "Smartsoltech", "url": "https://smartsoltech.kr", "new_window": True}
    ],


    "show_ui_builder": False,
    "show_ui_builder_breadcrumbs": False,
    "show_ui_builder_tabs": False,
    "show_ui_builder_tabs_breadcrumbs": False,

}
