"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");
const validation_1 = require("../../../validation");
exports.fields = {
    email: {
        id: 'email',
        label: 'Email',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'An email address that identifies a user profile in Iterable. Provide a recipient email or a recipient user ID, but not both, depending on how your project identifies users.',
    },
    userId: {
        id: 'userId',
        label: 'User ID',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'A user ID that identifies a user profile in Iterable. Provide a recipient email or a recipient user ID, but not both, depending on how your project identifies users.',
    },
    eventName: {
        id: 'eventName',
        label: 'Event name',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: '',
    },
    dataFields: {
        label: 'Data fields',
        id: 'dataFields',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'Additional data associated with event',
    },
};
exports.FieldsValidationSchema = zod_1.z
    .object({
    email: (0, extensions_core_1.makeStringOptional)(zod_1.z.string().email()),
    userId: (0, extensions_core_1.makeStringOptional)(zod_1.z.string()),
    eventName: zod_1.z.string(),
    dataFields: (0, extensions_core_1.makeStringOptional)(validation_1.StringTransformToJson),
})
    .superRefine((value, context) => {
    if ((0, lodash_1.isEmpty)(value.email) && (0, lodash_1.isEmpty)(value.userId)) {
        context.addIssue({
            code: zod_1.z.ZodIssueCode.custom,
            fatal: true,
            message: 'Both "email" and "user ID" are empty. Please provide one of them.',
        });
    }
    if (!(0, lodash_1.isEmpty)(value.email) && !(0, lodash_1.isEmpty)(value.userId)) {
        context.addIssue({
            code: zod_1.z.ZodIssueCode.custom,
            fatal: true,
            message: 'Both "email" and "user ID" are provided. Please provide only one of them.',
        });
    }
});
//# sourceMappingURL=fields.js.map