"""
Django settings for psr project.

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

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

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

from .common import *

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'ui@+$uk7y2phvbf0id$-%dcp%y6zmka7l-88y+!508bs0-%jfy')

ALLOWED_HOSTS = ['*']

# SECURITY WARNING: don't run with debug turned on in production!
DJANGO_DEBUG = os.environ.get('DJANGO_DEBUG', '')
if DJANGO_DEBUG == "True" or DJANGO_DEBUG == "true":
    DEBUG = True
else:
    DEBUG = False

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

# Specify here which localized databases are active. Users will be authenticated against databases in the given order
# always us the country ISO 3166 code
LOCALIZED_DATABASES = [
    'ca',
    'us',
]

# Add a new entry for any other additional country
# always us the country ISO 3166 code
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME', ''),
        'USER': os.environ.get('DB_USER', ''),
        'PASSWORD': os.environ.get('DB_PASSWORD', ''),
        'HOST': os.environ.get('DB_HOST', ''),
        'PORT': os.environ.get('DB_PORT', '5432'),
    },
    'ca': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('CA_DB_NAME', ''),
        'USER': os.environ.get('CA_DB_USER', ''),
        'PASSWORD': os.environ.get('CA_DB_PASSWORD', ''),
        'HOST': os.environ.get('CA_DB_HOST', ''),
        'PORT': os.environ.get('CA_DB_PORT', '5432'),
    },
    'us': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('US_DB_NAME', ''),
        'USER': os.environ.get('US_DB_USER', ''),
        'PASSWORD': os.environ.get('US_DB_PASSWORD', ''),
        'HOST': os.environ.get('US_DB_HOST', ''),
        'PORT': os.environ.get('US_DB_PORT', '5432'),
    }
}


# STORAGE
STATICFILES_STORAGE = 'psr.custom_storages.S3StaticStorage'
DEFAULT_FILE_STORAGE = 'psr.custom_storages.S3MediaStorage'


# AWS 
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME', '')
AWS_STORAGE_DOMAIN = os.environ.get('AWS_STORAGE_DOMAIN', '')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')

AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME', '') 
AWS_S3_SIGNATURE_VERSION = os.environ.get('AWS_S3_SIGNATURE_VERSION', 's3v4')

AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = True



# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_LOCATION = 'static'
MEDIAFILES_LOCATION = 'media'

STATIC_URL = "https://%s.%s/%s/" % (AWS_STORAGE_BUCKET_NAME, AWS_STORAGE_DOMAIN, STATICFILES_LOCATION)
MEDIA_URL = "https://%s.%s/%s/" % (AWS_STORAGE_BUCKET_NAME, AWS_STORAGE_DOMAIN, MEDIAFILES_LOCATION)


# STRIPE: payment gateway
STRIPE_SECRET_KEY = os.environ.get('STRIPE_SECRET_KEY', '')
STRIPE_WEBHOOK_SECRET = os.environ.get('STRIPE_WEBHOOK_SECRET', '')
STRIPE_YEARLY_PLAN_ID = os.environ.get('STRIPE_YEARLY_PLAN_ID', '')
STRIPE_MONTHLY_PLAN_ID = os.environ.get('STRIPE_MONTHLY_PLAN_ID', '')
STRIPE_YEARLY_FULL_PLAN_ID = os.environ.get('STRIPE_YEARLY_FULL_PLAN_ID', '')
STRIPE_MONTHLY_FULL_PLAN_ID = os.environ.get('STRIPE_MONTHLY_FULL_PLAN_ID', '')

# Email server configuration
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = os.environ.get('EMAIL_HOST', '')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', '')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', '')
EMAIL_PORT = os.environ.get('EMAIL_PORT', 587)
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', '')
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', '')

#  JWT token configuration
JWT_AUTH = {
    'JWT_PAYLOAD_HANDLER': 'rest_api.utils.custom_jwt_payload_handler',
    'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=int(os.environ.get('JWT_EXPIRATION_DELTA', 24))),
    'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(hours=int(os.environ.get('JWT_EXPIRATION_DELTA', 24))),
    'JWT_ALLOW_REFRESH': True
}

# 30min = 1800 seconds
PASSWORD_RESET_TOKEN_EXPIRES = int(os.environ.get('PASSWORD_RESET_TOKEN_EXPIRES', 1800))
# 7 days = 604800 seconds
USER_INVITE_TOKEN_EXPIRES = int(os.environ.get('USER_INVITE_TOKEN_EXPIRES', 604800))

# PSR APP details
PSR_APP_BASE_URL = os.environ.get('PSR_APP_BASE_URL', '')
PSR_API_BASE_URL = os.environ.get('PSR_API_BASE_URL', '')
PSR_APP_RESET_PASSWORD_PATH = os.environ.get('PSR_APP_RESET_PASSWORD_PATH', '')
PSR_APP_CONFIRM_ACCOUNT_PATH = os.environ.get('PSR_APP_CONFIRM_ACCOUNT_PATH', '')
PSR_APP_USER_INVITE_PATH = os.environ.get('PSR_APP_USER_INVITE_PATH', '')
PSR_APP_USER_LOGIN_PATH = os.environ.get('PSR_APP_USER_LOGIN_PATH', '')

DISABLE_EXPIRED_CUSTOMERS_TOKEN = os.environ.get('DISABLE_EXPIRED_CUSTOMERS_TOKEN',
                                                 'nAEoscqJ5DM3CXch6t&ZvDbt5kR1xce5FDbv#6d1XPGwaCd%LUr@^T5ThUA$a*y4')

HELP_CENTER_FORM_EMAILS = ['matt@personalsportrecord.com', 'steve@personalsportrecord.com']
HELP_CENTER_ORG_SUPPORT_FORM_EMAILS = ['matt@personalsportrecord.com', 'steve@personalsportrecord.com']

