"""
Django settings for config project.

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

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

from pathlib import Path

import environ

env = environ.Env()

BASE_DIR = Path(__file__).resolve().parent.parent

environ.Env.read_env()

DJANGO_ENV = os.getenv('DJANGO_ENV')

if DJANGO_ENV == 'production':
    environ.Env.read_env(os.path.join(BASE_DIR, 'config', 'env', 'production.env'))
else:
    environ.Env.read_env(os.path.join(BASE_DIR, 'config', 'env', 'local.env'))


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')


# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = env.bool('DEBUG')
DEBUG = True

ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')

CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_ALL_ORIGINS = True

# CORS_ALLOW_ALL_HEADERS = True

CORS_ALLOW_HEADERS = ["authorization", 'credentials', 'content-type']

CSRF_TRUSTED_ORIGINS = ['https://127.0.0.1:8000', 'https://homylio.com']


INSTALLED_APPS = [
    # 'django.contrib.admin',
    'daphne',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'corsheaders',
    'rest_framework_simplejwt',
    'accounts',
    'dashboard',
    'categories',
    'banners',
    'pages',
    'sub_categories',
    'chats',
    'works',
    'contracts',
    'channels',
    'notifications'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    "corsheaders.middleware.CorsMiddleware",
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'config.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',
            ],
        },
    },
]

# WSGI_APPLICATION = 'config.wsgi.application'
ASGI_APPLICATION = 'config.asgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'HOMYLIO',
        'USER': 'root',
        'PASSWORD': 'homylio@prod@234',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

# 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 = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ]
}

SIMPLE_JWT = {
    'JWT_VERIFY_EXPIRATION': False,
}



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


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

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

STATIC_URL = '/static/'

if DJANGO_ENV == 'local':
    STATICFILES_DIRS = [BASE_DIR / "static"]
else:
    STATIC_ROOT = os.path.join(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'

AUTH_USER_MODEL = 'accounts.users'
AUTHENTICATION_BACENDS = ['accounts.EmailBackEnd.EmailBackEnd']

LOGIN_URL='/admin/authentication/login'
LOGIN_REDIRECT_URL='/admin/authentication/login'


APPEND_SLASH=False

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

FAST2SMS_URL = "https://www.fast2sms.com/dev/otp/send"
FAST2SMS_AUTH_KEY = "mt9v56rzl8jpeEVsO0nPKaZ7GX1kJTcCWLR4uQqAowIfHixyDhObrYyJ9TwmodN8HkREFhVjC4AIPStW"
FAST2SMS_OTP_ID = "6eab6c7b8e"

LOGO_URL = "https://gangs.co.in/static/admin/images/logo-dark.png"
SERVER_URL = "https://gangs.co.in/media/"

FIREBASE_CREDENTIALS_PATH = BASE_DIR / "homylio-firebase-adminsdk-fbsvc-1dc70585ed.json"
FCM_URL = "https://fcm.googleapis.com/v1/projects/homylio/messages:send"

