"""Shared API response helpers."""

from quart import jsonify


def error_response(
    error: str, *, status: int = 400, detail: str | None = None, **extra,
):
    """JSON error body + HTTP status. `detail` is included only when given;
    `extra` keys are merged into the body. Returns the (response, status)
    tuple Quart expects. Imported as `_bad` by the blueprints."""
    body = {"error": error}
    if detail is not None:
        body["detail"] = detail
    body.update(extra)
    return jsonify(body), status
