import os
import logging

G_APPNAME = 'EMPTY-APP'
G_VERSION = '0.0.1'
G_EMAIL = 'innodev@synapsoft.co.kr'


class Config(object):
    DEBUG = False
    TESTING = False

    # Information
    APPNAME = G_APPNAME
    VERSION = G_VERSION
    EMAIL = G_EMAIL

    # Define the application directory
    BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

    # Temporary Directory
    TEMP_DIR = os.path.join(BASE_DIR, 'data/temp')
    if os.path.exists(TEMP_DIR) is False:
        os.mkdir(TEMP_DIR)

    UPLOAD_DIR = os.path.join(BASE_DIR, 'data/upload')
    if os.path.exists(UPLOAD_DIR) is False:
        os.mkdir(UPLOAD_DIR)

    # Define the database - we are working with
    # TODO DB 사용시 DB 설정에 따라 아래 값을 수정합니다.
    # DB_USER = 'flask'
    # DB_PASSWORD = 'ekfrhsk'
    # DB_ADDRESS = '127.0.0.1'
    # DB_PORT = '3306'
    # DB_DATABASE = 'flask1st'
    SQLALCHEMY_DATABASE_URI = f'sqlite:///:memory:'
    # SQLALCHEMY_DATABASE_URI = f'mysql+mysqlconnector://' \
    #                           f'{DB_USER}:{DB_PASSWORD}@' \
    #                           f'{DB_ADDRESS}:{DB_PORT}/' \
    #                           f'{DB_DATABASE}?charset=utf8'

    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # SQLALCHEMY_ENGINE_OPTIONS 사용 방법 https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine
    # SQLALCHEMY_ENGINE_OPTIONS = {'pool_size': 20,
    #                              'pool_recycle': -1,
    #                              'pool_timeout': 30,
    #                              'max_overflow': 10}

    # Application threads. A common general assumption is
    # using 2 per available processor cores - to handle
    # incoming requests using one and performing background
    # operations using the other.
    THREADS_PER_PAGE = 4

    # Enable protection agains *Cross-site Request Forgery (CSRF)*
    CSRF_ENABLED = False

    # Use a secure, unique and absolutely secret key for
    # signing the data.
    CSRF_SESSION_KEY = "SYNAP-INNO-SECRET"

    # Secret key for signing cookies
    SECRET_KEY = "SYNAP-INNO-COOKIES-SECRET"

    # set logdir
    LOG_DIR = os.path.join(BASE_DIR, 'data/logs')
    if os.path.exists(LOG_DIR) is False:
        os.mkdir(LOG_DIR)
    LOG_FILE = '{}.log'.format(G_APPNAME)
    LOG_LEVEL = logging.DEBUG

    # for reverse proxy
    ENABLE_PROXY_FIX = True


class ProductionConfig(Config):
    LOG_LEVEL = logging.WARN


class DevelopmentConfig(Config):
    DEBUG = True
    LOG_FILE = '{}-dev.log'.format(G_APPNAME)


class TestingConfig(Config):
    TESTING = True


