from flask import Flask
from decouple import config
import config as cfg


class FlaskApplication:

    # WARNING: Don't run with debug turned on in production!
    def __init__(self) -> None:
        self.app = None
        self.debug = config('DEBUG', default=False, cast=bool)
        # The configuration
        self.config_mode = 'Debug' if self.debug else 'Production'
        self.config = cfg.config_dict[self.config_mode.capitalize()]

    def register_blueprints(self, app):
        from app.main.engine.blueprint.main import MainController
        service = MainController(app)
        service.blueprints()
        blueprint = service.get_blueprint()
        return blueprint

    def create_app(self):
        self.app = Flask(__name__)
        self.app.logger.setLevel(cfg.conf["logging"])
        self.app.config.from_object(self.config)
        blueprint = self.register_blueprints(self.app)
        self.app.register_blueprint(blueprint)
        return self.app
