from pathlib import Path

from flask import Flask

try:
    from dotenv import load_dotenv
    load_dotenv(Path(__file__).resolve().parents[1] / ".env")
except Exception:
    pass


def create_app():
    app = Flask(__name__)

    @app.get("/health")
    def health():
        return {"success": True, "status": "online", "service": "vyneric-news-python"}

    try:
        from app.routes.prepare import prepare_bp
        app.register_blueprint(prepare_bp)
    except Exception:
        app.config["PREPARE_IMPORT_ERROR"] = True

    return app


app = create_app()
