"""Основные настройки приложения."""

import os


BASE_DIR = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__)),
)
SRC_DIR = os.path.join(BASE_DIR, '..')

_ENV_VAR = 'VAR_PATH'
VAR_PATH = os.getenv(_ENV_VAR, os.path.join(SRC_DIR, 'var'))

SECRET_KEY = '$h0ep7)x$p5s&^0q9j9%&5f7xm)p&ar5!w*lj3!s8aam#+2ax2'

DEBUG = True

ALLOWED_HOSTS = ('*',)

CORS_ORIGIN_ALLOW_ALL = True

DJANGO_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)


THIRD_PARTY_APPS = (
    'drf_yasg',
    'rest_framework.authtoken',
    'rest_auth',
    'corsheaders',
)

LOCAL_APPS = (
    'vacation_visualiser.api.employee',
    'vacation_visualiser.api.vacation',
    'vacation_visualiser.api.vacation_history',
)

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

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

ROOT_URLCONF = 'vacation_visualiser.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates', ), ],  # noqa: С819
        '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',
            ],
        },
    },
]

AUTH_USER_MODEL = 'employee.Employee'

ACCOUNT_EMAIL_VERIFICATION = 'none'

SWAGGER_SETTINGS = {
    'SECURITY_DEFINITIONS': {
        'Bearer': {
            'type': 'apiKey',
            'name': 'Authorization',
            'in': 'header',
        },
    },
    'DOC_EXPANSION': 'none',
}

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_FILTER_BACKENDS': (
        ('django_filters.rest_framework.DjangoFilterBackend', )
    )
}

REST_AUTH_SERIALIZERS = {
    'LOGIN_SERIALIZER': (
        'vacation_visualiser.api.employee.serializers.CustomLoginSerializer'
    ),
}

WSGI_APPLICATION = 'vacation_visualiser.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'vacation_visualiser.sqlite3'),
    },
}

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'
        ),
    },
)

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'Asia/Vladivostok'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

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

for path in (VAR_PATH, MEDIA_ROOT):
    if not os.path.exists(path):
        os.mkdir(path)
