"""
Django settings for DAIManagement project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
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/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+_s2$au87!#n98au7s=m0r6j6&$#jvb*0-%j-(mtioeh-p)dxc'

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

ALLOWED_HOSTS = ['207.180.254.4', '127.0.0.1']

# APPEND_SLASH=False

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'corsheaders',
    'django.contrib.staticfiles',
    'DAIManagementApp.apps.DaimanagementappConfig',
    'rest_framework'
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    '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',
    # timout middeware
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django_session_timeout.middleware.SessionTimeoutMiddleware',

    # 'rest_framework',
]

USE_THOUSAND_SEPARATOR = True

ALLOWED_HOSTS=['*']
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
# CORS_ALLOWED_ORIGINS = [
#     '*'
# ]
# CORS_ALLOWED_ORIGIN_REGEXES = [
#     '*'
# ]

# CORS_ORIGIN_ALLOW_ALL = False
# CORS_ORIGIN_WHITELIST = ('http://localhost:8000',)

ROOT_URLCONF = 'DAIManagement.urls'

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

# here !!!!!!!!
# TELEGRAM = {
#     'bot_token': '2024755752:AAHlirx4jfSRnUNv1dKUIJBwxWIaz0VVKHU',
#     'channel_name': 'realtime_adbreaks',
# }


# TELEGRAM = {
#     'bot_token': '5522894419:AAE9CeONlV2lfmUGqbXGZAHC-l1Z90TMuD4',
#     'chat_id':"-1001778433367",
#     'channel_name': 'EPG',
# }

# # #
TELEGRAM = {
    'bot_token': '2135410897:AAH14rU1sjvyP2WqD7lNAgMeYRNinofm4oE',
    'channel_name': 'adtlasbot',
}

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

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

# # =======================================
# # Database access on Mohammed's machine
# # =======================================
# DATABASES = {
#         'default': {
#             'ENGINE': 'django.db.backends.mysql',
#             'NAME': 'django_dai3',
#             'HOST': '127.0.0.1',
#             'PORT': '3306',
#             'USER': 'root',
#             'PASSWORD': '',
#         }
#     }
# # =======================================

# # =======================================
# # Database access on Brahim's machine
# # =======================================
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'daimanagement',
#         'HOST': '127.0.0.1',
#         'PORT': '3306',
#         'USER': 'root',
#         'PASSWORD': 'brahim123',
#     }
# }
# # =======================================

# # =======================================
# # Database access on Ayoub's machine
# # =======================================
# #
# DATABASES = {
#         'default': {
#             'ENGINE': 'django.db.backends.mysql',
#             'NAME': 'dai_management',
#             'HOST': '127.0.0.1',
#             'PORT': '3306',
#             'USER': 'root',
#             'PASSWORD': '',
#         }
#     }
 # =======================================

## =======================================
## Database access on Server
## =======================================
DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.mysql',
       'NAME': 'Django_DAI',
       'HOST': 'localhost',
       'PORT': '3306',
       'USER': 'root',
       'PASSWORD': 'Root123!',
   }
}
## =======================================


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

MEDIA_ROOT = os.path.join(BASE_DIR,'/media/')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]


XMLFILES_URL = '/files/'
XMLFILES_DIRS = [
    os.path.join(BASE_DIR, "files"),
]

appurl = "/DAIManagement/"
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# <<<<<<< HEAD
# <<<<<<< HEAD
SESSION_EXPIRE_SECONDS = 1800   # 30 min
# =======
SESSION_EXPIRE_SECONDS = 1800  # 30 min
# >>>>>>> 52faab9ced1512e32449917c260b8603389a24b1
# =======

SESSION_EXPIRE_SECONDS = 7200  # 30 min
# >>>>>>> bc4c2444318d19f66764b36fed4ea78294332de4
SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True
SESSION_TIMEOUT_REDIRECT = appurl+'logout'

# local logs
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "root": {"level": "INFO", "handlers": ["file"]},
    "handlers": {
        "file": {
            "level": "INFO",
            "class": "logging.FileHandler",
            "filename": "logs/django.log",
            "formatter": "app",
        },
    },
    "loggers": {
        "django": {
            "handlers": ["file"],
            "level": "INFO",
            "propagate": True
        },
    },
    "formatters": {
        "app": {
            "format": (
                u"%(asctime)s [%(levelname)-8s] "
                "(%(module)s.%(funcName)s) %(message)s"
            ),
            "datefmt": "%Y-%m-%d %H:%M:%S",
        },
    },
}

# settings.py
CELERY_BROKER_URL = 'redis://0.0.0.0:6379/0'  # URL to connect to Redis
CELERY_RESULT_BACKEND = 'redis://0.0.0.0:6379/0'  # Store task results in Redis