import os
import sys
from flask_migrate import Migrate
from apps.config import config_dict
from apps import create_app, db

sys.path.insert(0, os.path.dirname(__file__))

DEBUG = os.getenv('DEBUG', 'False') == 'True'
get_config_mode = 'Debug' if DEBUG else 'Production'

try:
    app_config = config_dict[get_config_mode.capitalize()]
except KeyError:
    sys.exit('Error: Invalid <config_mode>. Expected values [Debug, Production]')

app = create_app(app_config)
Migrate(app, db)

if DEBUG:
    app.logger.info('DEBUG            = ' + str(DEBUG)             )
    app.logger.info('Page Compression = ' + 'FALSE' if DEBUG else 'TRUE' )
    app.logger.info('DBMS             = ' + app_config.SQLALCHEMY_DATABASE_URI)
    app.logger.info('ASSETS_ROOT      = ' + app_config.ASSETS_ROOT )

def run(environ, start_response):
    return app(environ, start_response)

if __name__ == "__main__":
    app.run(debug=True)