# -*- coding: utf-8 -*-
"""Application configuration."""

from __future__ import absolute_import, division, print_function, unicode_literals

import os

from . import __author__, __name__, __version__


class Config(object):
    """Base configuration."""

    SERVER_NAME = os.environ.get('SERVER_NAME', None)
    PREFERRED_URL_SCHEME = os.environ.get('PREFERRED_URL_SCHEME', 'http')
    APP_NAME = __name__
    APP_VERSION = __version__
    APP_AUTHOR = __author__
    JSON_AS_ASCII = False
    SECRET_KEY = os.environ.get('XL_AUTH_SECRET', 'secret-key')  # TODO: Change me
    APP_DIR = os.path.abspath(os.path.dirname(__file__))  # This directory.
    PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir))
    BCRYPT_LOG_ROUNDS = 13
    DEBUG_TB_ENABLED = False  # Disable Debug toolbar.
    DEBUG_TB_INTERCEPT_REDIRECTS = False
    CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc.
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    WEBPACK_MANIFEST_PATH = 'webpack/manifest.json'
    BABEL_DEFAULT_LOCALE = os.environ.get('BABEL_DEFAULT_LOCALE', 'sv')
    BABEL_DEFAULT_TIMEZONE = 'utc'
    EMAIL_DEFAULT_FROM = os.environ.get('EMAIL_DEFAULT_FROM', 'noreply@kb.se')
    EMAIL_HOST = os.environ.get('EMAIL_HOST', 'smtp.kb.se')
    EMAIL_PORT = int(os.environ.get('EMAIL_PORT', '25'))
    EMAIL_TIMEOUT = int(os.environ.get('EMAIL_TIMEOUT', '5'))
    OAUTH2_PROVIDER_TOKEN_EXPIRES_IN = 36000
    XL_AUTH_MAX_ACTIVE_PASSWORD_RESETS = 2
    XL_AUTH_FAILED_LOGIN_TIMEFRAME = 60 * 60
    XL_AUTH_FAILED_LOGIN_MAX_ATTEMPTS = 7


class ProdConfig(Config):
    """Production configuration."""

    ENV = 'prod'
    DEBUG = False
    SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI',
                                             'postgresql://localhost/example')
    DEBUG_TB_ENABLED = False  # Disable Debug toolbar.


class DevConfig(Config):
    """Development configuration."""

    ENV = 'dev'
    DEBUG = True
    DB_NAME = 'dev.db'
    # Put the db file in project root
    DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
    SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
    DEBUG_TB_ENABLED = True
    CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc.


class TestConfig(Config):
    """Test configuration."""

    TESTING = True
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'sqlite://'
    # For faster tests; needs at least 4 to avoid "ValueError: Invalid rounds".
    BCRYPT_LOG_ROUNDS = 4
    WTF_CSRF_ENABLED = False  # Allows form testing.
    EMAIL_BACKEND = 'flask_emails.backends.DummyBackend'

[((14, 18, 14, 53), 'os.environ.get', 'os.environ.get', ({(14, 33, 14, 46): '"""SERVER_NAME"""', (14, 48, 14, 52): 'None'}, {}), "('SERVER_NAME', None)", False, 'import os\n'), ((15, 27, 15, 73), 'os.environ.get', 'os.environ.get', ({(15, 42, 15, 64): '"""PREFERRED_URL_SCHEME"""', (15, 66, 15, 72): '"""http"""'}, {}), "('PREFERRED_URL_SCHEME', 'http')", False, 'import os\n'), ((20, 17, 20, 63), 'os.environ.get', 'os.environ.get', ({(20, 32, 20, 48): '"""XL_AUTH_SECRET"""', (20, 50, 20, 62): '"""secret-key"""'}, {}), "('XL_AUTH_SECRET', 'secret-key')", False, 'import os\n'), ((29, 27, 29, 71), 'os.environ.get', 'os.environ.get', ({(29, 42, 29, 64): '"""BABEL_DEFAULT_LOCALE"""', (29, 66, 29, 70): '"""sv"""'}, {}), "('BABEL_DEFAULT_LOCALE', 'sv')", False, 'import os\n'), ((31, 25, 31, 78), 'os.environ.get', 'os.environ.get', ({(31, 40, 31, 60): '"""EMAIL_DEFAULT_FROM"""', (31, 62, 31, 77): '"""noreply@kb.se"""'}, {}), "('EMAIL_DEFAULT_FROM', 'noreply@kb.se')", False, 'import os\n'), ((32, 17, 32, 59), 'os.environ.get', 'os.environ.get', ({(32, 32, 32, 44): '"""EMAIL_HOST"""', (32, 46, 32, 58): '"""smtp.kb.se"""'}, {}), "('EMAIL_HOST', 'smtp.kb.se')", False, 'import os\n'), ((46, 30, 47, 78), 'os.environ.get', 'os.environ.get', ({(46, 45, 46, 70): '"""SQLALCHEMY_DATABASE_URI"""', (47, 45, 47, 77): '"""postgresql://localhost/example"""'}, {}), "('SQLALCHEMY_DATABASE_URI', 'postgresql://localhost/example')", False, 'import os\n'), ((58, 14, 58, 56), 'os.path.join', 'os.path.join', ({(58, 27, 58, 46): 'Config.PROJECT_ROOT', (58, 48, 58, 55): 'DB_NAME'}, {}), '(Config.PROJECT_ROOT, DB_NAME)', False, 'import os\n'), ((21, 30, 21, 55), 'os.path.dirname', 'os.path.dirname', ({(21, 46, 21, 54): '__file__'}, {}), '(__file__)', False, 'import os\n'), ((22, 35, 22, 67), 'os.path.join', 'os.path.join', ({(22, 48, 22, 55): 'APP_DIR', (22, 57, 22, 66): 'os.pardir'}, {}), '(APP_DIR, os.pardir)', False, 'import os\n'), ((33, 21, 33, 55), 'os.environ.get', 'os.environ.get', ({(33, 36, 33, 48): '"""EMAIL_PORT"""', (33, 50, 33, 54): '"""25"""'}, {}), "('EMAIL_PORT', '25')", False, 'import os\n'), ((34, 24, 34, 60), 'os.environ.get', 'os.environ.get', ({(34, 39, 34, 54): '"""EMAIL_TIMEOUT"""', (34, 56, 34, 59): '"""5"""'}, {}), "('EMAIL_TIMEOUT', '5')", False, 'import os\n')]