import { parseDef as p } from "../parseDef.js";
const u = {
  ZodString: "string",
  ZodNumber: "number",
  ZodBigInt: "integer",
  ZodBoolean: "boolean",
  ZodNull: "null"
};
function c(i, s) {
  if (s.target === "openApi3")
    return l(i, s);
  const r = i.options instanceof Map ? Array.from(i.options.values()) : i.options;
  if (r.every((e) => e._def.typeName in u && (!e._def.checks || !e._def.checks.length))) {
    const e = r.reduce((n, t) => {
      const o = u[t._def.typeName];
      return o && !n.includes(o) ? [...n, o] : n;
    }, []);
    return {
      type: e.length > 1 ? e : e[0]
    };
  } else if (r.every((e) => e._def.typeName === "ZodLiteral" && !e.description)) {
    const e = r.reduce((n, t) => {
      const o = typeof t._def.value;
      switch (o) {
        case "string":
        case "number":
        case "boolean":
          return [...n, o];
        case "bigint":
          return [...n, "integer"];
        case "object":
          if (t._def.value === null)
            return [...n, "null"];
        case "symbol":
        case "undefined":
        case "function":
        default:
          return n;
      }
    }, []);
    if (e.length === r.length) {
      const n = e.filter((t, o, a) => a.indexOf(t) === o);
      return {
        type: n.length > 1 ? n : n[0],
        enum: r.reduce((t, o) => t.includes(o._def.value) ? t : [...t, o._def.value], [])
      };
    }
  } else if (r.every((e) => e._def.typeName === "ZodEnum"))
    return {
      type: "string",
      enum: r.reduce((e, n) => [
        ...e,
        ...n._def.values.filter((t) => !e.includes(t))
      ], [])
    };
  return l(i, s);
}
const l = (i, s) => {
  const r = (i.options instanceof Map ? Array.from(i.options.values()) : i.options).map((e, n) => p(e._def, {
    ...s,
    currentPath: [...s.currentPath, "anyOf", `${n}`]
  })).filter((e) => !!e && (!s.strictUnions || typeof e == "object" && Object.keys(e).length > 0));
  return r.length ? { anyOf: r } : void 0;
};
export {
  c as parseUnionDef,
  u as primitiveMappings
};
//# sourceMappingURL=union.js.map
