"""
Django settings for project project.

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

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-=1u*cm37s=w*h^e(w@8rccl_&j0e0lw_r4v7p)jx1)e!*t2znk'

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #Internal
    'master',
    'user',
    #external
    'channels',
    'rest_framework',
    'rest_framework.authtoken',
    'drf_yasg',
    'corsheaders',
]

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

ROOT_URLCONF = 'project.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application' 
ASGI_APPLICATION = 'project.asgi.application'


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

#for testing

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

#Produnction

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'chat',
        'USER': 'doadmin',
        'PASSWORD': 'AVNS_4fhELUJsdduOth_',
        'HOST': 'db-mysql-blr1-58301-do-user-8394763-0.b.db.ondigitalocean.com',
        'PORT': '25060',
    }
}


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
        'master.authentication.BearerAuthentication'
    ]
}


CORS_ALLOWED_ORIGINS = [
    'https://chatpythonscript-testing.harmonicalling.com',
    "http://localhost:8001",
]

CORS_ORIGIN_ALLOW_ALL = True


# Used to generate password reset URLs
FRONTEND_URL = "https://chatbackend-testing.harmonicalling.com/#"


DEFAULT_FROM_EMAIL = "kamesh.ninositsolution@gmail.com"


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'kamesh.ninositsolution@gmail.com'
EMAIL_HOST_PASSWORD = 'uett hnhj hisr jglt'


MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'


#s3 credentioanls

# settings.py

import os

DO_SPACES_KEY = os.environ.get('DIGITALOCEAN_SPACES_KEY')
DO_SPACES_SECRET = os.environ.get('DIGITALOCEAN_SPACES_SECRET')
DO_SPACES_REGION = os.environ.get('DIGITALOCEAN_SPACES_REGION', 'sgp1')
DO_SPACES_BUCKET = os.environ.get('DIGITALOCEAN_SPACES_BUCKET')
DO_SPACES_ENDPOINT = os.environ.get('DIGITALOCEAN_SPACES_ENDPOINT', 'https://sgp1.digitaloceanspaces.com')
DO_SPACES_CDN_ENDPOINT = os.environ.get('DIGITALOCEAN_SPACES_CDN_ENDPOINT', 'https://sgp1.cdn.digitaloceanspaces.com')


# RAZORPAY
RAZORPAY_KEY_ID = os.environ.get("RAZORPAY_KEY_ID")
RAZORPAY_KEY_SECRET = os.environ.get("RAZORPAY_KEY_SECRET")



CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [('127.0.0.1', 6379)],
        },
    },
}


import os
from pythonjsonlogger import jsonlogger

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
            'format': '%(asctime)s %(levelname)s %(name)s %(message)s',
        },
    },
    'handlers': {
        'json_file': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'admin_password_reset.log'),
            'formatter': 'json',
        },
    },
    'loggers': {
        'admin_reset': {
            'handlers': ['json_file'],
            'level': 'INFO',
            'propagate': False,
        },
    },
}
