"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.literals = exports.unionLiterals = exports.anyFunction = exports.partialObj = exports.json = exports.primitive = exports.chained = exports.arrayOrNot = void 0;
const zod_1 = require("zod");
function arrayOrNot(schema, params) {
    return zod_1.z.union([zod_1.z.array(schema), schema], params);
}
exports.arrayOrNot = arrayOrNot;
function chained(config, utils, params) {
    const ret = zod_1.z.union([config, zod_1.z.void()]);
    const fn = utils
        ? zod_1.z.function(zod_1.z.tuple([config, utils]), ret)
        : zod_1.z.function(zod_1.z.tuple([config]), ret);
    const combined = zod_1.z.union([config, fn]);
    return arrayOrNot(combined, params);
}
exports.chained = chained;
const primitive = () => {
    const literalSchema = zod_1.z.union([
        zod_1.z.string(),
        zod_1.z.number(),
        zod_1.z.boolean(),
        zod_1.z.null(),
        zod_1.z.undefined(),
    ]);
    return literalSchema;
};
exports.primitive = primitive;
const json = () => {
    const jsonSchema = zod_1.z.lazy(() => zod_1.z.union([(0, exports.primitive)(), zod_1.z.array(jsonSchema), zod_1.z.record(jsonSchema)]));
    return jsonSchema;
};
exports.json = json;
const partialObj = (src) => {
    return zod_1.z.object(src).partial();
};
exports.partialObj = partialObj;
const anyFunction = () => zod_1.z.function();
exports.anyFunction = anyFunction;
const unionLiterals = (literals) => {
    const wraps = literals.map(value => zod_1.z.literal(value));
    return zod_1.z.union(wraps);
};
exports.unionLiterals = unionLiterals;
exports.literals = exports.unionLiterals;
__exportStar(require("zod"), exports);
__exportStar(require("zod-validation-error"), exports);
