"""
Django settings for aft project.

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

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

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

import os
import environ
from corsheaders.defaults import default_headers

CWD = os.path.dirname(os.path.realpath(__file__))
"""
    Setup Environmental variables
"""
REMOTE_DATABASE_HOST = 'mongodb+srv://SirDavid:fluffygate@indeepshipcluster.7rnt2.mongodb.net/NavisAlbumData?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority'

env = environ.Env(
    DEBUG=(bool, True),
    SERVER_ADDRESS=(str, 'http://127.0.0.1:3000'),
    DATABASE_HOST=(str, REMOTE_DATABASE_HOST)
)

environ.Env.read_env(env_file=os.path.join(CWD, '..', '.env'))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=dgyvs=_jn(8mn1ouh4l_*=o)q=y88bsn0sjd5_lvpl3bnn&(9'

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

# ALLOWED_HOSTS = ['206.189.218.111', '127.0.0.1', 'localhost']
ALLOWED_HOSTS = ["*"]

CORS_ALLOW_HEADERS = default_headers + ('api-key',)

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'corsheaders',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'allauth',
    'allauth.account',
    'rest_auth.registration',
    'api',
    'users',
    'vesselregistration',
    'payments'
]

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = 'Navis Album DRS <noreply@navisalbum.com>'
# EMAIL_HOST="localhost"

# Site id is the id of the site_name to use from the django_site table.
# This option changes the site_name and domain in the email sent by
# password reset.
# SITE_ID = 79 is 127.0.0.1:3000 (for testing)
# SITE_ID = 81 is 206.189.218.111 (for production)
SITE_ID = 79

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 = 'aft.urls'

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


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

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'CLIENT': {
            'name': 'NavisAlbumData',
            'host': 'mongodb+srv://SirDavid:fluffygate@indeepshipcluster.7rnt2.mongodb.net/NavisAlbumData?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority',
            'username': 'SirDavid',
            'password': 'fluffygate',
            'authMechanism': 'SCRAM-SHA-1'
        }
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.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/2.2/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/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

SLACK_WEBHOOK = 'https://hooks.slack.com/services/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'
ACCOUNT_UNIQUE_EMAIL = True
AUTH_USER_MODEL = 'users.CustomUser'

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'users.serializers.UserSerializer',
    'TOKEN_SERIALIZER': 'users.serializers.CustomTokenSerializer'
}

REST_AUTH_REGISTER_SERIALIZERS = {
    'REGISTER_SERIALIZER': 'users.serializers.CustomRegisterSerializer',
}

OLD_PASSWORD_FIELD_ENABLED = True

# allow cross site requests from any origin
CORS_ORIGIN_ALLOW_ALL = True
# CORS_ORIGIN_WHITELIST = (
#     'http://127.0.0.1:3000', 'http://127.0.0.1:8000', 'http://localhost:3000', 'http://localhost:8000'
# )

# allow cookies to be included in cross site requests
CORS_ALLOW_CREDENTIALS = True

# allow cookies to be returned for cross site requests
SESSION_COOKIE_SAMESITE = None
CSRF_COOKIE_SAMESITE = None

# allow client side javascript to access the CRSF and session cookies
SESSION_COOKIE_HTTPONLY = False
CSRF_COOKIE_HTTPONLY = False

# Since we're not using HTTPS
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False

"""
    IP Addreses for development and deployment url redirects
"""
SERVER_ADDRESS = env('SERVER_ADDRESS')
