import { isDereferenced as p } from "@scalar/openapi-types/helpers";
function d(t, i) {
  var s;
  let o = t;
  const e = (s = i.required) == null ? void 0 : s.includes(t);
  return o += e ? " REQUIRED " : " optional ", i.properties[t] && (o += i.properties[t].type, i.properties[t].description && (o += " " + i.properties[t].description)), o;
}
function h(t) {
  var e;
  const i = ["Body"], o = (e = t == null ? void 0 : t.schema) == null ? void 0 : e.properties;
  return o && Object.keys(o).forEach((s) => {
    if (!t.schema)
      return;
    i.push(d(s, t.schema));
    const r = o[s];
    r.type === "object" && !!r.properties && r.properties && Object.keys(r.properties).forEach((n) => {
      var c, f;
      i.push(`${n} ${(f = (c = r.properties) == null ? void 0 : c[n]) == null ? void 0 : f.type}`);
    });
  }), i;
}
function q(t) {
  var i, o;
  try {
    const e = (o = (i = t == null ? void 0 : t.requestBody) == null ? void 0 : i.content) == null ? void 0 : o["application/json"];
    if (!e)
      throw new Error("Body not found");
    return h(e);
  } catch {
    return !1;
  }
}
function u(t, i) {
  for (const [o, e] of Object.entries(t))
    e !== null && typeof e == "object" ? (i[o] ?? (i[o] = new e.__proto__.constructor()), u(e, i[o])) : typeof e < "u" && (i[o] = e);
  return i;
}
function E(t) {
  return u(t ?? {}, {
    info: {
      title: "",
      description: "",
      termsOfService: "",
      version: "",
      license: {
        name: "",
        url: ""
      },
      contact: {
        email: ""
      }
    },
    servers: [],
    tags: []
  });
}
function O(t) {
  const i = {
    path: [],
    query: [],
    header: [],
    cookie: [],
    body: [],
    formData: []
  }, o = t.parameters ?? [];
  return o && o.forEach((e) => {
    p(e) && (typeof e == "object" && e !== null && "$ref" in e || (e.in === "path" ? i.path.push(e) : e.in === "query" ? i.query.push(e) : e.in === "header" ? i.header.push(e) : e.in === "cookie" ? i.cookie.push(e) : e.in === "body" ? i.body.push(e) : e.in === "formData" && i.formData.push(e)));
  }), i;
}
export {
  E as createEmptySpecification,
  O as createParameterMap,
  u as deepMerge,
  q as extractRequestBody,
  d as formatProperty
};
