import os


class Config:
    ACTIVE_CONFIG = "app.config.Prod"

    @staticmethod
    def configure_app(config="prod"):
        if config.lower() == "prod":
            Config.ACTIVE_CONFIG = 'app.config.Prod'
        elif config.lower() == "debug":
            Config.ACTIVE_CONFIG = 'app.config.Debug'
        elif config.lower() == "test":
            Config.ACTIVE_CONFIG = 'app.config.Test'
        else:
            raise Exception('{} n\'est pas configuration une configuration valide'.format(config))

    DEBUG = False
    TESTING = False
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))
    SQLALCHEMY_DATABASE_URI = \
        'sqlite:///' + os.path.join(BASE_DIR, '../app.db')
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    THREADS_PER_PAGE = 2
    SECRET_KEY = "secret"
    BUNDLE_ERRORS = True
    SESSION_COOKIE_SECURE = True
    SESSION_VALIDITY_DURATION_WITHOUT_ACTIVITY_MIN = 20


class Prod(Config):
    SQLALCHEMY_DATABASE_URI = 'mysql://user@localhost/foo'


class Debug(Config):
    DEBUG = True
    SESSION_COOKIE_SECURE = False
    SQLALCHEMY_DATABASE_URI = 'mysql://ola:XXX@localhost/OLA'


class Test(Config):
    TESTING = True
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))
    SQLALCHEMY_DATABASE_URI = \
        'sqlite:///' + os.path.join(BASE_DIR, '../test.db')