"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 = {
    list: {
        id: 'list',
        label: 'List',
        description: 'The list you want to transform to a comma separated text.',
        type: extensions_core_1.FieldType.STRING_ARRAY,
        required: true,
    },
};
exports.FieldsValidationSchema = zod_1.z.object({
    list: zod_1.z
        .unknown()
        .optional()
        .transform((val, ctx) => {
        if ((0, lodash_1.isNil)(val) || (0, lodash_1.isEmpty)(val))
            return [];
        if (typeof val === 'string') {
            try {
                const parsedJson = JSON.parse(val);
                if ((0, lodash_1.isEmpty)(parsedJson)) {
                    return [];
                }
                if (!Array.isArray(parsedJson)) {
                    ctx.addIssue({
                        code: 'custom',
                        message: 'Not an array',
                    });
                    return zod_1.z.NEVER;
                }
                return parsedJson;
            }
            catch (e) {
                ctx.addIssue({
                    code: 'custom',
                    message: 'Not a valid JSON object',
                });
                return zod_1.z.NEVER;
            }
        }
        return val;
    }),
});
//# sourceMappingURL=fields.js.map