from __future__ import annotations

from flask import jsonify


def json_error(message: str, status: int):
    return jsonify({"error": message}), status


def map_offer_fetch_errors(
    errors: list[str] | None,
    *,
    not_found_message: str,
    generic_message: str,
):
    if errors and "offer.not_found" in errors:
        return json_error(not_found_message, 404)
    return json_error(generic_message, 500)

