from flask import Blueprint, jsonify

from backend.readiness import get_payload, get_status

health_bp = Blueprint("health", __name__, url_prefix="/health")


@health_bp.route("/ready", methods=["GET"])
def readiness():
    payload = get_payload()
    status = get_status()
    if status == "ready":
        status_code = 200
    elif status == "failed":
        status_code = 500
    else:
        status_code = 503
    return jsonify(payload), status_code
