"""
Django settings for NavyaBackers project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

from datetime import timedelta
from pathlib import Path
import os
import logging

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-ro8b9%wus50udq%c-17u7#-2tib3equcqx#%8tw@5f)!654jq1"

# Encryption key for encrypted fields
FIELD_ENCRYPTION_KEY = 'fS2nyVQdxwpeNQ_HbiITrZXrOBBwhKSR1U8h5JNpzSs='

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

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
    'daphne',
    'channels',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
    'shops',
    'rest_framework',
    'rest_framework_simplejwt',
    'products',
    'rest_framework.authtoken',
    'corsheaders',
    'orders',
    'dal',
    'dal_select2',
    'django_celery_beat',
    'chatbot',
    'cms',
    'ckeditor'
]

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",
]

CORS_ALLOW_ALL_ORIGINS = True

ROOT_URLCONF = "NavyaBackers.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",
            ],
            'libraries': {
                'dictops': 'chatbot.templatetags.dictops',

            }
        },
    },
]

#
ASGI_APPLICATION = "NavyaBackers.asgi.application"
# WSGI_APPLICATION = 'NavyaBackers.wsgi.application'
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
    },
}


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

# change database

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',

        'NAME': 'navya_bakers2',

        'USER': 'postgres',

        'PASSWORD': 'PassWord@1137',

        'HOST': 'localhost',

        'PORT': '5432',

    }

}


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

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 6
}


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

LANGUAGE_CODE = "en-us"

TIME_ZONE = "Asia/Kolkata"

USE_I18N = True

USE_TZ = True


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


STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfile")
STATICFILES_DIRS = [
    BASE_DIR / "static",
]
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"

SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(days=162),
    # "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
    "USER_ID_FIELD": "uuid",
}

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


EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
# EMAIL_HOST_USER='uudd13298@gmail.com'
# EMAIL_HOST_PASSWORD='qkqx lqvz xfqt rfbn'
EMAIL_HOST_USER = "navyabakeshop12@gmail.com"
EMAIL_HOST_PASSWORD = "uibd swyy fmei fddx"
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
DEFAULT_FROM_EMAIL = "navyabakeshop12@gmail.com"

LOGIN_URL = "/adminportal/login/"

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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
AUTH_USER_MODEL = "accounts.Users"


AUTHENTICATION_BACKENDS = [
    'accounts.authentication.PhoneNumberBackend',
    "django.contrib.auth.backends.ModelBackend",
]

LOGGING = {
    "version": 1,
    # The version number of our log
    "disable_existing_loggers": False,
    "formatters": {
        "file": {"format": "%(asctime)s %(name)-12s %(levelname)-8s: %(message)s"}
    },
    # django uses some of its own loggers for internal operations. In case you want to disable them just replace the False above with true.
    # A handler for WARNING. It is basically writing the WARNING messages into a file called WARNING.log
    "handlers": {
        "file": {
            "level": "INFO",
            "class": "logging.FileHandler",
            "filename": BASE_DIR / "info.log",
            "formatter": "file",
        },
    },
    # A logger for WARNING which has a handler called 'file'. A logger can have multiple handler
    "loggers": {
        # notice the blank '', Usually you would put built in loggers like django or root here based on your needs
        "": {
            "handlers": [
                "file"
            ],  # notice how file variable is called in handler which has been defined above
            "level": "INFO",
            "propagate": True,
        },

    },
}


CELERY_BROKER_URL = 'redis://localhost:6379/0'  # Redis broker
CELERY_ACCEPT_CONTENT = ['json']         # Content to accept (JSON)
CELERY_TASK_SERIALIZER = 'json'          # Task serializationA
CELERY_RESULT_SERIALIZER = 'json'        # Result serialization
CELERY_TIMEZONE = 'UTC'                  # Set timezone if necessary



CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'

RAZORPAY_KEY_ID = 'rzp_test_cmarNFsgeNJcxi'
RAZORPAY_KEY_SECRET = 'Hd4ez1MR2814J5c9Ua9yyAaH'


# whatsapp_ACCESS_TOKEN = 'EAAWlGJjPDukBO4xOwMFr8WRpgfg2fLyfBjZCK0WRr4GxdY0U0JhSUUZCHnC3U6xHtT8Tz3i3ZAt0kzEi9TQZAmHO2ik2NJ5tPWkyJSe2gWPhysQ7OsvpTijcxcOOVfNsjQC591HXhN7I55VGLd4t28z46EgR71KuKwLREeaP6dTc3v982zlbW44ZBUvxK0ZAjbbYEvwUW7Kt0XWf30r4gRmyCrNs0ZD'
# whatsapp_PHONE_NUMBER_ID = '513696815140821'