"""
Django settings for config project.

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

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 = 'vrpl2*u64cxc3ew17!a25xe0w7tdq=5dqv2j+t)9))vd5y#%gc'

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

    # CORS
    'corsheaders',

    # DRF
    'rest_framework',
    # 'rest_framework.authtoken',

    # rest_auth + allauth
    # 'rest_auth',
    # 'allauth',
    # 'allauth.account',
    # 'rest_auth.registration',

    # Hashtag
    'taggit.apps.TaggitAppConfig',
    'taggit_templatetags2',

    # Apps
    'accounts.apps.AccountsConfig',
    'posts',
    'board',
    'index',
    'search',
]

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',
    'corsheaders.middleware.CorsMiddleware',
]

CORS_ORIGIN_WHITELIST = [
    'http://localhost:8080',
    'http://127.0.0.1:8080'
]

CORS_ALLOW_CREDENTIALS = True

TAGGIT_CASE_INSENSITIVE = True

MIDDLEWARE_CLASSES = MIDDLEWARE

ROOT_URLCONF = 'config.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 = 'config.wsgi.application'


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

DATABASES = {
    'default': {
        'OPTIONS' : {
            'init_command' : "SET sql_mode='STRICT_TRANS_TABLES'",
        },
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pocs',
        'USER': '',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

# 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 = 'ko-kr'

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/'

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ]
}

SITE_ID = 1

APPEND_SLASH = False

MEDIA_ROOT = BASE_DIR / 'media'
MEDIA_URL = '/media/'

FILE_MEDIA_DIR = 'files'
BACKGROUND_IMAGES_MEDIA_DIR = 'backgroundImages'

DEFAULT_IMAGE_RELATIVE_PATH = f'{BACKGROUND_IMAGES_MEDIA_DIR}/default/default_background_image.jpg'

MAX_FILE_UPLOAD_SIZE = 104857600
MAX_FILE_UPLOAD_SIZE_TO_UNIT_NOTATION = '100MB'
'''
64KB = 65536
512KB = 524288
1MB = 1048576
100MB = 104857600
500MB = 524288000
1GB = 1073741824
'''

ALLOWED_FILE_EXTENTIONS = (
    'hwp', 'ppt', 'pptx', 'xlsx', 'xls', 'cell', 'show', 'pdf', 'doc', 'docx', 'csv', # 문서 파일 확장자
    'avi', 'mp4', 'mov', 'wmv', # 비디오 파일 확장자
    'txt',  # 텍스트 파일 확장자
    'zip', '7z',  # 압축 파일 확장자
    'jpg', 'jpeg', 'gif', 'png', 'bmp',   # 이미지 파일 확장자
)

MAX_TAG_COUNT_IN_POST = 10

MAX_BOARD_CATEGORY_LEVEL = 5

# Session cookie
# https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-SESSION_COOKIE_DOMAIN

# SESSION_COOKIE_DOMAIN = 'localhost:8000'
