import { computed as i, ref as T, provide as t } from "vue";
import { useDiscriminator as C, DISCRIMINATOR_CONTEXT as d, EXAMPLE_CONTEXT as p } from "./useDiscriminator.js";
function E(e) {
  return e ? !!(e.discriminator || e.type === "array" && e.items && typeof e.items == "object" && "discriminator" in e.items) : !1;
}
function j(e, f) {
  var c, m, o;
  const n = (o = (m = (c = e == null ? void 0 : e.requestBody) == null ? void 0 : c.content) == null ? void 0 : m["application/json"]) == null ? void 0 : o.schema, a = i(() => E(n)), h = a.value ? C({
    schema: n,
    schemas: f,
    onSchemaChange: (r) => {
      var u, l;
      (l = (u = e == null ? void 0 : e.requestBody) == null ? void 0 : u.content) != null && l["application/json"] && (e.requestBody.content["application/json"].schema = r);
    }
  }) : {
    selectedType: T(""),
    discriminatorMapping: i(() => ({})),
    discriminatorPropertyName: i(() => ""),
    hasDiscriminator: i(() => !1),
    mergedSchema: i(() => n),
    generateExampleValue: () => ({})
  }, {
    selectedType: s,
    discriminatorMapping: y,
    discriminatorPropertyName: g,
    hasDiscriminator: v,
    mergedSchema: D,
    generateExampleValue: S
  } = h;
  if (a.value) {
    const r = i(() => ({
      selectedType: s.value || void 0,
      discriminatorMapping: y.value || {},
      discriminatorPropertyName: g.value || "",
      hasDiscriminator: v.value,
      mergedSchema: D.value
    }));
    t(d, r), t(p, {
      generateExampleValue: S
    });
  } else
    t(
      d,
      i(() => null)
    ), t(p, {
      generateExampleValue: () => ({})
    });
  return {
    hasSchemaDiscriminator: a,
    handleDiscriminatorChange: (r) => {
      a.value && (s.value = r);
    }
  };
}
export {
  j as useOperationDiscriminator
};
