"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
exports.fields = {
    json: {
        id: 'json',
        label: 'JSON',
        description: 'The data object you would like to stringify',
        type: extensions_core_1.FieldType.JSON,
        required: true,
    },
};
exports.FieldsValidationSchema = zod_1.z.object({
    json: zod_1.z
        .string()
        .min(1)
        .trim()
        .transform((str, ctx) => {
        if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str)) {
            return {};
        }
        try {
            const parsedJson = JSON.parse(str);
            if ((0, lodash_1.isEmpty)(parsedJson)) {
                return {};
            }
            if (typeof parsedJson !== 'object' || Array.isArray(parsedJson)) {
                ctx.addIssue({
                    code: 'custom',
                    message: 'JSON input is not a valid object',
                });
                return zod_1.z.NEVER;
            }
            return parsedJson;
        }
        catch (e) {
            ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
            return zod_1.z.NEVER;
        }
    }),
});
//# sourceMappingURL=fields.js.map