"""Runtime graph interaction endpoints.

Dashboard configuration CRUD lives in ``factory_dashboard_api.py``. This
blueprint intentionally owns only graph-runtime requests so future graph
interactions can evolve without coupling them to dashboard persistence.
"""

from flask import Blueprint, current_app, jsonify, request

from services import auth_service


graphing_api_bp = Blueprint("graphing_api", __name__)


def _json_error(message: str, status_code: int):
    return jsonify({"success": False, "message": message}), status_code


@graphing_api_bp.route("/api/dashboard/plot-clicked", methods=["POST"])
@auth_service.login_required("web.home_page")
def plot_clicked():
    """Receive a clicked graph point. Business handling will be added later."""
    payload = request.get_json(silent=True)
    if not isinstance(payload, dict):
        return _json_error("JSON body is required", 400)

    # Intentionally empty: keep this runtime contract stable while downstream
    # behavior is decided. Logging is useful during integration and can be
    # removed after the future handler is added.
    current_app.logger.info("Dashboard plot clicked: %s", payload)
    return jsonify({"success": True, "received": True}), 202
