import os

import configuration as CONFIG
# Added for Heroku
import django_heroku
import dj_database_url
from decouple import config
################## End of Heroku imports
"""
Django settings for dentist_base project.

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

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

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

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+$ur=nyr4vdx10l=euuy4f9v8fwdy292l%5a9gaik9*&m1-2if'

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

MIDDLEWARE = [
    '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',
    'whitenoise.middleware.WhiteNoiseMiddleware', 
]

ROOT_URLCONF = 'dentist_base.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'dentist_base.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


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

STATIC_URL = '/static/'

#   Take path of our 'static' directory and join it to our BASE_DIR (automagically made by Django)
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

########################################################
#   Added for Heroku
# STATICFILES_STORAGE 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
 

# django_heroku.settings(locals())
########################################################


#  Step (3) Email Settings 
############################################################################   
#   ---> Step (4) is open up a new command line (and make sure were in VENV) to put in the cmd for SMTP
#           cmd:> python -m smtpd -n -c DebuggingServer localhost:1025
    # #       ---> Step (5) will be to send a 'Thank You' message name that we will recieve your email and respond shortly.. (in contact.html)
    # EMAIL_HOST = 'localhost'
    # EMAIL_PORT = 1025 # needs to be a number, not  a string...
    # EMAIL_HOST_USER = ''
    # EMAIL_HOST_PASSWORD = ''
    # EMAIL_USE_TLS = False

# STEPs for PRODUCTION CODE

#   (*) MUST DO FOR Emails to work..
# (1)   myaccount.google.com/lesssecureapps
# (2)   accounts.google.com/DisplayUnlockCaptcha

#   For ADDED Security
###################################################
# myaccount.google.com/apppasswords
    #   $ Setup 2-factor Oauth for Django Apps (this password will be the password used 
    # instead of our 'EMAIL_HOST_PASSWORD = CONFIG.PASSWORD' )
###################################################


#   Production Email settings
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
#   USING CONFIG as envireonment variable...
# email host user is the email address we want the email to route to
EMAIL_HOST_USER = CONFIG.EMAIL
#   password is the same user's password to GMAIL
EMAIL_HOST_PASSWORD = CONFIG.PASSWORD
EMAIL_USE_TLS = True

###################################################
#NOTE: Gmail doesnt allow 3rd party apps, therefore
###################################################
# if u use SSL you will need another port
#   For Production Use
#EMAIL_USE_SSL = False



#   Heroku setup
django_heroku.settings(locals())