from .base import *

# GET SECRET FROM ENVIRONMENT
get_secret = os.getenv

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

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

ALLOWED_HOSTS = ["obaa.xyz"]

AUTH_USER_MODEL = 'accounts.User'

BASE_URL = '127.0.0.1:8000'

# Application definition

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

    # Third Party
    'corsheaders',
    'rest_framework',
    'webpack_loader',

    # My APPS
    'accounts',
    'blog',
    'home',
    'tags',
]


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


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


# We whitelist localhost:3000 because that's where frontend will be served
CORS_ORIGIN_WHITELIST = (
    'localhost:5000/'
)


DEFAULT_FROM_EMAIL = get_secret('DEFAULT_FROM_EMAIL')
EMAIL_HOST = get_secret('EMAIL_HOST')


EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD')
EMAIL_PORT = get_secret('EMAIL_PORT')
EMAIL_USE_TLS = True


MANAGERS = (
    ('OBAA', get_secret('MANAGER_EMAIL')),
)
ADMINS = MANAGERS


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


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "static_root")


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

if DEBUG:
    WEBPACK_LOADER = {
        'DEFAULT': {
            'BUNDLE_DIR_NAME': 'bundles/',
            'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
        }
    }

else:
    WEBPACK_LOADER = {
        'DEFAULT': {
            'BUNDLE_DIR_NAME': 'prod/',
            'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-prod.json'),
        }
    }

# else:
#     WEBPACK_LOADER = {
#         'DEFAULT': {
#             'BUNDLE_DIR_NAME': 'test/',
#             'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-test.json'),
#         }
#     }


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'db',
        'PORT': 5432,
    }
}

# DATABASES = {
#     'default': {
#         'ENGINE': get_secret('DATABASE_ENGINE'),
#         'NAME': get_secret('DATABASE_NAME'),
#         'USER': get_secret('DATABASE_USER'),
#         'PASSWORD': get_secret('DATABASE_PASSWORD'),
#         'HOST': get_secret('DATABASE_HOST'),
#         'PORT': get_secret('DATABASE_PORT'),
#     }
# }

