import { XScalarStability as c } from "@scalar/types/legacy";
function u(e, r) {
  var s;
  let t = e;
  const i = (s = r.required) == null ? void 0 : s.includes(e);
  return t += i ? " REQUIRED " : " optional ", r.properties[e] && (t += r.properties[e].type, r.properties[e].description && (t += " " + r.properties[e].description)), t;
}
function d(e) {
  var i;
  const r = ["Body"], t = (i = e == null ? void 0 : e.schema) == null ? void 0 : i.properties;
  return t && Object.keys(t).forEach((s) => {
    if (!e.schema)
      return;
    r.push(u(s, e.schema));
    const n = t[s];
    n.type === "object" && !!n.properties && n.properties && Object.keys(n.properties).forEach((p) => {
      var f, a;
      r.push(`${p} ${(a = (f = n.properties) == null ? void 0 : f[p]) == null ? void 0 : a.type}`);
    });
  }), r;
}
function x(e) {
  var r, t;
  try {
    const i = (t = (r = e == null ? void 0 : e.requestBody) == null ? void 0 : r.content) == null ? void 0 : t["application/json"];
    if (!i)
      throw new Error("Body not found");
    return d(i);
  } catch {
    return !1;
  }
}
function O(e) {
  var t, i;
  if (!e)
    return {};
  const r = (
    // OpenAPI 3.x
    Object.keys(((t = e == null ? void 0 : e.components) == null ? void 0 : t.schemas) ?? {}).length ? (i = e == null ? void 0 : e.components) == null ? void 0 : i.schemas : (
      // Fallback
      {}
    )
  );
  return Object.keys(r ?? {}).forEach((s) => {
    var n, o;
    (((n = r[s]) == null ? void 0 : n["x-internal"]) === !0 || ((o = r[s]) == null ? void 0 : o["x-scalar-ignore"]) === !0) && delete r[s];
  }), r;
}
function l(e, r) {
  for (const [t, i] of Object.entries(e))
    i !== null && typeof i == "object" ? (r[t] ?? (r[t] = new i.__proto__.constructor()), l(i, r[t])) : typeof i < "u" && (r[t] = i);
  return r;
}
function E(e) {
  return l(e ?? {}, {
    info: {
      title: "",
      description: "",
      termsOfService: "",
      version: "",
      license: {
        name: "",
        url: ""
      },
      contact: {
        email: ""
      }
    },
    servers: [],
    tags: []
  });
}
function b(e) {
  return e.deprecated !== void 0 ? e.deprecated : !!(e["x-scalar-stability"] && e["x-scalar-stability"] === c.Deprecated);
}
function y(e) {
  return e.deprecated ? c.Deprecated : e["x-scalar-stability"];
}
function S(e) {
  const r = y(e);
  return r === c.Deprecated ? "text-red" : r === c.Experimental ? "text-orange" : r === c.Stable ? "text-green" : "";
}
export {
  E as createEmptySpecification,
  l as deepMerge,
  x as extractRequestBody,
  u as formatProperty,
  O as getModels,
  y as getOperationStability,
  S as getOperationStabilityColor,
  b as isOperationDeprecated
};
