"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonArraySchema = exports.JsonSchema = exports.StringTransformToJson = void 0;
const lodash_1 = require("lodash");
const zod_1 = require("zod");
exports.StringTransformToJson = zod_1.z
    .string()
    .transform((str, ctx) => {
    if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str))
        return {};
    try {
        return JSON.parse(str);
    }
    catch (e) {
        ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
        return zod_1.z.NEVER;
    }
});
exports.JsonSchema = exports.StringTransformToJson.transform((jsonObject, ctx) => {
    if ((0, lodash_1.isNil)(jsonObject) || (0, lodash_1.isEmpty)(jsonObject)) {
        ctx.addIssue({
            code: 'custom',
            message: 'The object should not be empty',
        });
        return zod_1.z.NEVER;
    }
    return jsonObject;
});
exports.JsonArraySchema = exports.StringTransformToJson.transform((jsonObject, ctx) => {
    if (!Array.isArray(jsonObject)) {
        ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
        return zod_1.z.NEVER;
    }
    return jsonObject;
});
//# sourceMappingURL=validation.js.map