"""
Django settings for current project.

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

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

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

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

BASE_URL = "http://127.0.0.1:8000/"

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "secret"

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

ALLOWED_HOSTS = [
    "*",
]

AUTH_USER_MODEL = "authentication.User"

# Application definition

INSTALLED_APPS = [
    "django.contrib.sites",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.humanize",
    "django.contrib.gis",
    "social_django",
    "django_extensions",
    "corsheaders",
    "taggit",
    "logpipe",
    "rest_framework",
    "rest_framework.authtoken",
    "drf_yasg",
    "enterprise.structures.authentication",
    "enterprise.structures.administrative",
    "enterprise.structures.common",
    "enterprise.structures.tracker",
    "enterprise.structures.integration",
    "core.structures.company",
    "core.structures.project",
    "core.structures.role",
]


MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.locale.LocaleMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "social_django.middleware.SocialAuthExceptionMiddleware",
]

ROOT_URLCONF = "project.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [
            os.path.join(BASE_DIR, "apps/home/templates"),
            os.path.join(BASE_DIR, "apps/superuser/templates"),
            os.path.join(BASE_DIR, "apps/authentication/templates"),
            os.path.join(BASE_DIR, "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",
                "social_django.context_processors.backends",
                "social_django.context_processors.login_redirect",
            ],
        },
    },
]

WSGI_APPLICATION = "project.wsgi.application"

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
        "OPTIONS": {
            "min_length": 8,
        },
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = "id"

LANGUAGES = [
    ("id", "Indonesia"),
    ("en", "English"),
]

TIME_ZONE = "Asia/Jakarta"

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale"),
    os.path.join(BASE_DIR, "../venv/src/panel/panel/locale"),
)


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

STATIC_URL = "/static/"
# STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    # 'compressor.finders.CompressorFinder',
)

# Media storage
MEDIA_ROOT = os.path.join(BASE_DIR, "upload")
STATICFILES_DIRS = [
    # ...
    os.path.join(BASE_DIR, "static"),
    ("upload", MEDIA_ROOT),
]


REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework.authentication.BasicAuthentication",
        "rest_framework.authentication.TokenAuthentication",
        "rest_framework.authentication.SessionAuthentication",
    ),
    "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
    "PAGE_SIZE": 20,
    "DEFAULT_PARSER_CLASSES": (
        "rest_framework.parsers.JSONParser",
        "rest_framework.parsers.FormParser",
    ),
    "DEFAULT_RENDERER_CLASSES": (
        "rest_framework.renderers.JSONRenderer",
        "rest_framework.renderers.BrowsableAPIRenderer",
    ),
    "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema",
    "DEFAULT_PERMISSION_CLASSES": (
        "rest_framework.permissions.IsAuthenticatedOrReadOnly",
    ),
}


# Social Auth
AUTHENTICATION_BACKENDS = (
    "social_core.backends.google.GoogleOAuth2",
    "django.contrib.auth.backends.ModelBackend",
)

SOCIAL_AUTH_PIPELINE = (
    "social_core.pipeline.social_auth.social_details",
    "social_core.pipeline.social_auth.social_uid",
    "social_core.pipeline.social_auth.auth_allowed",
    "social_core.pipeline.social_auth.social_user",
    "social_core.pipeline.user.get_username",
    "enterprise.libs.authentication.oauth_pipeline.create_user",
    "social_core.pipeline.social_auth.associate_user",
    "social_core.pipeline.social_auth.associate_by_email",
    "social_core.pipeline.social_auth.load_extra_data",
    "social_core.pipeline.user.user_details",
    "enterprise.libs.authentication.oauth_pipeline.update_user",
)


SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

SOCIAL_AUTH_URL_NAMESPACE = "social"

SOCIAL_AUTH_LOGIN_URL = "/auth/login/?next=/google-oauth2/"

SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/account"

SOCIAL_AUTH_LOGIN_ERROR_URL = "/login/?next=/"

SOCIAL_AUTH_POSTGRES_JSONFIELD = True

LOGIN_REDIRECT_URL = "/"

SOCIAL_AUTH_FACEBOOK_SCOPE = ["email"]
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    "fields": "id,name,email",
}

SOCIAL_AUTH_FACEBOOK_API_VERSION = "2.10"


SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ["r_basicprofile", "r_emailaddress"]
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = [
    "email-address",
    "formatted-name",
    "public-profile-url",
]
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [
    ("id", "id"),
    ("formattedName", "name"),
    ("emailAddress", "email_address"),
    ("publicProfileUrl", "profile_url"),
]

# flatpage
if NEWS_ENABLED:
    INSTALLED_APPS.append("django.contrib.flatpages")
    MIDDLEWARE.append("django.contrib.flatpages.middleware.FlatpageFallbackMiddleware")

# crispy
CRISPY_TEMPLATE_PACK = "bootstrap4"

# Markdown
MARKDOWN_DEUX_STYLES = {
    "default": {
        "extras": {
            "code-friendly": None,
            "tables": 1,
        },
        "safe_mode": "escape",
    },
}


# Email configurations
FROM_EMAIL = "Email"
EMAIL_HOST = "smtp.mailgun.org"
EMAIL_PORT = 587
EMAIL_HOST_USER = "askme"
EMAIL_HOST_PASSWORD = "askme"

AUTO_VERIFY_EMAIL = False

USE_RACKSPACE = False

RACKSPACE_CLOUD_FILES = {
    "username": "askme",
    "key": "askme",
    "region": "askme",
    "default_container": "askme",
}

SWAGGER_SETTINGS = {
    "SECURITY_DEFINITIONS": {
        "api_key": {"type": "apiKey", "in": "header", "name": "Authorization"}
    },
    "USE_SESSION_AUTH": False,
}

NEXMO_API_KEY = "askme"
NEXMO_API_SECRET = "askme"

COMPANY_BANK_ACCOUNT = "nomor_rekening"

try:
    from .local_settings import *
except BaseException:
    pass

LOGPIPE = {
    # Required Settings
    "OFFSET_BACKEND": "logpipe.backend.kafka.ModelOffsetStore",
    "CONSUMER_BACKEND": "logpipe.backend.kafka.Consumer",
    "PRODUCER_BACKEND": "logpipe.backend.kafka.Producer",
    "KAFKA_BOOTSTRAP_SERVERS": ["localhost:9092"],
    "KAFKA_CONSUMER_KWARGS": {
        "group_id": "recommendation",
    },
}


SITE_ID = 1
