from flask import Blueprint, request, jsonify
import app.extensions.rabbitmq as rabbitmq_mod
import json

notification_bp = Blueprint('notification', __name__, url_prefix='/notification')

@notification_bp.route('/', methods=['POST'], strict_slashes=False)
def send_notification():
    data = request.get_json()
    if not data:
        return jsonify({"error": "Empty JSON payload"}), 400


    message = json.dumps(data)

    client = rabbitmq_mod.get_rabbitmq_client()
    try:
        client.publish_message(message)
        return jsonify({"status": "message queued"}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 500
