# 配置插件注册的信息的操作在此脚本进行
"""
    -环境分类:
        1-开发环境:(开发人员进行开发) debug=True                          ------>未上线
        2-测试环境:(测试人员进行测试,找出bug交给开发人员进行修复维护) Testting = False  ------>未上线
        3-演示环境:(模拟真实环境,进行数据交互)                           ------>未上线

        4-生产环境:(客户使用环境)                                         ------>已上线
config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False 跟踪对象修改模式

"""


# 定义数据库uri路径
def get_database_uri(DATABASE):
    db = DATABASE.get('DB') or 'mysql'
    driver = DATABASE.get('DRIVER') or 'pymysql'
    user = DATABASE.get('USER') or 'root'
    password = DATABASE.get('PASSWORD') or '123456'
    host = DATABASE.get('HOST') or '127.0.0.1'
    port = DATABASE.get('PORT') or '3306'
    dbname = DATABASE.get('DBNAME') or 'flask_env'

    return '{}+{}://{}:{}@{}:{}/{}'.format(db, driver, user, password, host, port, dbname)


# 配置基类
class BaseConfig:
    DEBUG = False
    TESTING = False
    SQLALCHEY_TRACK_MODIFICATIONS = False
    SECRET_KEY = 'lfowefafds#$%^&^%$fwoeilkajldfk12'


# 开发环境
class DevelopConfig(BaseConfig):
    DEBUG = True
    # 其余类属性不用继承

    DATABASE = {
        'DB': 'mysql',
        'DRIVER': 'pymysql',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'DBNAME': 'flask_deve'
    }

    SQLALCHEY_DATABASE_URI = get_database_uri(DATABASE)


# 测试环境
class TestingConfig(BaseConfig):
    Testing = True
    # 其余类属性不用继承

    DATABASE = {
        'DB': 'mysql',
        'DRIVER': 'pymysql',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'DBNAME': 'flask_test'
    }

    SQLALCHEY_DATABASE_URI = get_database_uri(DATABASE)


# 演示环境
class StagingConfig(BaseConfig):
    # 其余类属性不用继承

    DATABASE = {
        'DB': 'mysql',
        'DRIVER': 'pymysql',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'DBNAME': 'flask_stag'
    }

    SQLALCHEY_DATABASE_URI = get_database_uri(DATABASE)


# 生产环境
class ProductConfig(BaseConfig):
    DEBUG = True
    # 其余类属性不用继承

    DATABASE = {
        'DB': 'mysql',
        'DRIVER': 'pymysql',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'DBNAME': 'flask_prod'
    }

    SQLALCHEY_DATABASE_URI = get_database_uri(DATABASE)


config = {
    'develop': DevelopConfig,
    'testing': TestingConfig,
    'staging': StagingConfig,
    'product': ProductConfig,
    'default': DevelopConfig,  # 这里设置默认环境为开发环境
}
