function o(f, e = 0) {
  return e >= 20 || !Array.isArray(f) || f.length === 0 ? {} : f.reduce((p, r) => {
    if (!r || typeof r != "object")
      return p;
    if (r.allOf) {
      const i = o(r.allOf, e + 1);
      return o([p, i], e + 1);
    }
    const t = typeof p == "object" ? { ...p } : {};
    if (r.properties && (t.properties = n(t.properties || {}, r.properties, e + 1)), r.items) {
      if (r.type === "array")
        t.items = O(t.items || {}, r.items, e + 1);
      else if (r.type === "object" && r.items.allOf) {
        const i = o(r.items.allOf, e + 1);
        t.properties = n(
          t.properties || {},
          i.properties || {},
          e + 1
        );
      }
    }
    return m(t, r, e + 1);
  }, {});
}
function n(f, e, p = 0) {
  if (p >= 20)
    return f;
  const r = typeof f == "object" ? { ...f } : {};
  return Object.entries(e).forEach(([t, i]) => {
    var s;
    if (!i || typeof i != "object") {
      r[t] = i;
      return;
    }
    if (!r[t]) {
      i.type === "array" && ((s = i.items) != null && s.allOf) ? r[t] = {
        ...i,
        items: o(i.items.allOf, p + 1)
      } : i.allOf ? r[t] = o(i.allOf, p + 1) : r[t] = i;
      return;
    }
    if (i.allOf)
      r[t] = o([r[t], ...i.allOf], p + 1);
    else if (i.type === "array" && i.items)
      r[t] = {
        ...r[t],
        type: "array",
        items: O(r[t].items || {}, i.items, p + 1)
      };
    else {
      const l = r[t].properties || i.properties ? n(r[t].properties || {}, i.properties || {}, p + 1) : void 0;
      r[t] = {
        ...r[t],
        ...i
      }, l && (r[t].properties = l);
    }
  }), r;
}
function O(f, e, p = 0) {
  if (p >= 20)
    return f;
  if (f.allOf || e.allOf) {
    const t = [...f.allOf || [f], ...e.allOf || [e]];
    return o(t, p + 1);
  }
  const r = {
    ...f,
    ...e
  };
  return (r.properties || e.properties) && (r.properties = n(r.properties || {}, e.properties || {}, p + 1)), r;
}
const m = (f, e, p = 0) => {
  if (p >= 20)
    return f;
  const r = typeof f == "object" ? { ...f } : {};
  return e.required && Array.isArray(e.required) && (r.required = [...f.required || [], ...e.required]), e.type && !f.type && (r.type = e.type), e.title && !f.title && (r.title = e.title), e.name && !f.name && (r.name = e.name), e.description && !f.description && (r.description = e.description), ["oneOf", "anyOf"].forEach((t) => {
    const i = e[t];
    i && i.forEach((s) => {
      s.properties && (r.properties = n(r.properties || {}, s.properties, p + 1));
    });
  }), r;
};
export {
  o as mergeAllOfSchemas
};
