
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from microblog.config import Config


mail = Mail()
db = SQLAlchemy()
bicrypt = Bcrypt()
login_manager = LoginManager()
login_manager.login_view = 'users_bp.login'
login_manager.login_message_category = 'info'


def create_app(config_class=Config):

    app = Flask(__name__)
    app.config.from_object(Config)
    mail.init_app(app)
    db.init_app(app)
    bicrypt.init_app(app)
    login_manager.init_app(app)

    from microblog.main.routes import main_bp
    from microblog.users.routes import users_bp
    from microblog.posts.routes import posts_bp
    from microblog.errors.handlers import errors_bp
    
    app.register_blueprint(users_bp)
    app.register_blueprint(posts_bp)
    app.register_blueprint(main_bp)
    app.register_blueprint(errors_bp)


    return app
