"""
Django settings for saas_template project.

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

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

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

import os
import datetime

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm0l&kk2@*yzohs_18$fu%e0nfvo)ez_i1dz%p7ty@=n^nm6jt_'

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'corsheaders',
    'channels',
    'crispy_forms',
    'django_countries',

    'core',
    'products',
    'discounts',
    'stores',
    'messaging',
    'emailmarketing',
    'customers',
    'payments',
    'billing',
    'themes',
    'sites'
]

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

ROOT_URLCONF = 'saas_template.urls'
SUBDOMAIN_URLCONF = 'saas_template.subdomain_urls'
SUBDOMAIN_USE_ROOT = [None, "www", "api", "coursepropeller"]


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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'saastemplate',
        'USER': 'saastemplate',
        'PASSWORD': 'saastemplate',
        'HOST': os.getenv('DB_HOST', 'postgresql'),
        'PORT': os.getenv('DB_PORT', '5432'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'OPTIONS': {
            'min_length': 9,
        }
    }
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/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.0/howto/static-files/
STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static")
]

AUTH_USER_MODEL = 'core.User'
AUTHENTICATION_BACKENDS = ['core.backends.StoreAuthBackend']

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DATETIME_FORMAT': "%m/%d/%Y %H:%M:%S",
    'DATETIME_INPUT_FORMATS': ["%m/%d/%Y %H:%M:%S",],
    'DATE_INPUT_FORMATS': ["%m/%d/%Y"]
}

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': datetime.timedelta(minutes=5),
    'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=1),
    'ROTATE_REFRESH_TOKENS': True,
    'USER_ID_CLAIM': 'id'
}

CORS_ORIGIN_ALLOW_ALL = True

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = 'AKIAVJ7PEJZC2LPVGAB6'
AWS_SECRET_ACCESS_KEY = '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'
AWS_STORAGE_BUCKET_NAME = 'courses-user-upload-test'
AWS_DEFAULT_ACL = None


JWPLAYER_KEY = "ePHCR86y"
JWPLAYER_SECRET = "hFhEjpDFFPdXAVKS3S0elw5p"
JWPLAYER_PLAYER_ID = "VRgZnDrY"


# Channels
REDIS_URL = os.getenv('REDIS_URL', 'redis://redis:6379')

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [REDIS_URL],
        },
    },
}

ASGI_APPLICATION = 'saas_template.routing.application'

STRIPE_SECRET_KEY = "sk_test_oLuDYwWz4mwromTtbZpYWmzf"
STRIPE_PUBLISHABLE_KEY = "pk_test_Cc4vyxuVdrWoaH9IdjZo6tlN"
STRIPE_CONNECT_WEBHOOK_SECRET = "whsec_isbS1yNZZ1JhuAuGNIVIuqpfzVmUVq35"
STRIPE_CONNECT_CLIENT_ID = "ca_HVQCKCg6N15wc7PvVBrllvo5vKAIHuAc"
STRIPE_CONNECT_REDIRECT_URL = "http://localhost:3000/store/payments/"
STRIPE_PRICE_IDS = {
    "basic": "price_1GwQopJGIlbculkw29I6rVXC",
    "premium": "price_1GwpaRJGIlbculkwD9QYcRNl"
}
STRIPE_PORTAL_RETURN_URL = "http://localhost:3000/dashboard"

CRISPY_TEMPLATE_PACK = 'bootstrap4'

# LOGGING = {
#     'version': 1,
#     'disable_existing_loggers': False,
#     'handlers': {
#         'console': {
#             'level': 'DEBUG',
#             'class': 'logging.StreamHandler',
#         }
#     },
#     'loggers': {
#         'django.db.backends': {
#             'handlers': ['console'],
#             'level': 'DEBUG',
#         },
#     }
# }


# Email
DEFAULT_RECOVERY_KEY_VALID_DAYS = 1
EMAIL_ADDRESS_RECOVER_PASSWORD = "noreply@coursepropeller.com"

# Sendgrid
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'evandempsey'
EMAIL_HOST_PASSWORD = 'uhjgysdasd854i9'


LOGIN_URL = "/login/"
LOGIN_REDIRECT_URL = "/dashboard/"

APP_DOMAIN = "coursepropeller.com"

X_FRAME_OPTIONS = 'SAMEORIGIN'
