from flask import Flask
from flask_login import LoginManager

from project.users import User


def create_app():

    app = Flask(__name__)

    app.config.from_pyfile('settings.py')

    # todo: delete this print under
    # print(app.config['SECRET_KEY'])

    # blueprint for auth routes in our app
    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    # blueprint for non-auth parts of app
    from .app import main as main_blueprint
    app.register_blueprint(main_blueprint)

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(user_id: str):
        return User.get(user_id)

    return app


