from flask import Flask
from flask_migrate import Migrate
from flask_wtf.csrf import CSRFProtect
from dotenv import load_dotenv

from extensions import db, login_manager
from playlist import bp as playlist_bp
from auth import bp as auth_bp

load_dotenv()

def create_app():
    app = Flask(__name__)
    app.secret_key = "!spotifyweather1234!"
    CSRFProtect(app) #aktivera csrf skydd i hela applikationen

    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    db.init_app(app)
    Migrate(app, db)

    login_manager.init_app(app)

    app.register_blueprint(playlist_bp)
    app.register_blueprint(auth_bp)

    return app

app = create_app()

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