import os
from flask import Flask, url_for
from flask_sqlalchemy import SQLAlchemy


from lyrics import paginas

def create_app():
    app = Flask(__name__)
    app.config.from_prefixed_env()

    app.config['SECRET_KEY'] = 'secret-key-goes-here'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///songs.db'
    app.config['UPLOAD_FOLDER'] = os.path.join(app.instance_path, 'uploads')
    app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024  # 16 MB máximo

    from .models import db

    db.init_app(app)

    from . import models

    with app.app_context():
        db.create_all()

#    basededatos.init_app(app)

    app.register_blueprint(paginas.bp)

    print(f"Current Environment: {os.getenv('ENVIRONMENT')}")
    print(f"Using Database: {app.config.get('DATABASE')}")
    print(f"Directorio de uploads: {app.config.get('UPLOAD_FOLDER')}")
    print(f"instance: {app.instance_path}")

    return app

