"""
Django settings for djangoProject project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import datetime
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
from django.conf import settings

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.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-p^_*8q*auqe(p^@5-6q#$_&i0nj8031ex#2acjs_hdtesqzom2'

# 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',
    'django.contrib.sites',
    'haystack',
    # thrid apps
    'django_extensions',
    'debug_toolbar',
    'corsheaders',
    'django_filters',
    #'social_django',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.kakao',
    'allauth.socialaccount.providers.naver',
    'rest_framework.authtoken',
    'rest_auth',
    # locals apps
    'film',
    'login',

    'rest_framework',
    'drf_multiple_model',
    #'knox', # 나중에 회원 가입, 인증에 활용 예정
]

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

]
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
# CORS_ORIGIN_WHITELIST = (
#     'http://localhost:8080',  # vue의 포트 번호
#     'http://127.0.0.1:8080',
#     'http://localhost:8000',  # django의 포트 번호
#     'http://127.0.0.1:8000',
# )


ROOT_URLCONF = 'djangoProject.urls'
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ os.path.join(BASE_DIR, 'film', '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 = 'djangoProject.wsgi.application'


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

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR , 'db.sqlite3'),
        # MariaDB 연동
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'film',
        'USER': 'film',
        'PASSWORD': 'film01q1w2e3',
        'HOST': '3.37.62.95',
        'PORT': '3306',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.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/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'film', 'static'),
]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

INTERNAL_IPS = ['127.0.0.1']

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field


# Oauth 영역
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTHENTICATION_BACKENDS = [

    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',

]
SITE_ID = 1
LOGIN_REDIRECT_URL = '/film/'
SOCIALACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_FORMS = {
                    'add_email': 'allauth.account.forms.AddEmailForm',
}
AUTH_USER_MODEL = 'login.User'
# ACCOUNT_USER_MODEL_USERNAME_FIELD = None # 사용자 이름 대신 이메일 사용
ACCOUNT_EMAIL_REQUIRED = True # 사용자 등록시 확인 링크로 이메일 확인 메시지 보내기
ACCOUNT_UNIQUE_EMAIL = True # 메일 고유성 확인
# ACCOUNT_USERNAME_REQUIRED = True # 가입시 사용자 이름 입력 X
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_VERIFICATION = 'none'

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
        # 'django_filters.rest_framework.DjangoFilterBackend',
    'rest_framework.authentication.TokenAuthentication',
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',

    ],
    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'
    ],
}
# JWT_AUTH = {
#     'JWT_SECRET_KEY': settings.SECRET_KEY,
#     'JWT_ALGORITHM': 'HS256',
#     'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
#     'JWT_ALLOW_REFRESH': True,
#     'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
# }
# REST_USE_JWT = True

SOCIALACCOUNT_PROVIDERS = {
    'kakao': {
        'APP': {
            'client_id': '3d961dbb12a532f3120d8a5a7f0db730',
            'secret': '586673',
            'key': ''
        }
    },
    'google':{
        'APP':{
            'client_id': '919070184360-3v52kcpgd92ga1mq1qb417ctiqabko6v.apps.googleusercontent.com',
            'secret': 'AIzaSyDobG99B7WfrjQ0SdEi5rTO-RKSbT0Bmww',
            'key':''

        }
    },
    'naver': {
        'APP': {
            'client_id': 'Fr0D7K07ckqEJ77ZBbFT',
            'secret': 'QUMCAJm3XK',
            'key': ''

        }
    }
}
