"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 = {
    campaignId: {
        label: 'Campaign ID',
        id: 'campaignId',
        type: extensions_core_1.FieldType.NUMERIC,
        required: true,
        description: '',
    },
    recipientEmail: {
        label: 'Recipient email',
        id: 'recipientEmail',
        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.',
    },
    recipientUserId: {
        label: 'Recipient user ID',
        id: 'recipientUserId',
        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.',
    },
    dataFields: {
        label: 'Data fields',
        id: 'dataFields',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'Fields to merge into email template.',
    },
    allowRepeatMarketingSends: {
        label: 'Allow repeat marketing sends?',
        id: 'allowRepeatMarketingSends',
        type: extensions_core_1.FieldType.BOOLEAN,
        required: false,
        description: 'Defaults to true.',
    },
    metadata: {
        label: 'Metadata',
        id: 'metadata',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'Metadata to pass back via webhooks. Not used for rendering.',
    },
};
exports.FieldsValidationSchema = zod_1.z
    .object({
    campaignId: extensions_core_1.NumericIdSchema,
    recipientEmail: (0, extensions_core_1.makeStringOptional)(zod_1.z.string().email()),
    recipientUserId: (0, extensions_core_1.makeStringOptional)(zod_1.z.string()),
    dataFields: (0, extensions_core_1.makeStringOptional)(validation_1.StringTransformToJson),
    allowRepeatMarketingSends: zod_1.z.boolean().optional(),
    metadata: (0, extensions_core_1.makeStringOptional)(validation_1.StringTransformToJson),
})
    .superRefine((value, context) => {
    if ((0, lodash_1.isEmpty)(value.recipientEmail) && (0, lodash_1.isEmpty)(value.recipientUserId)) {
        context.addIssue({
            code: zod_1.z.ZodIssueCode.custom,
            fatal: true,
            message: 'Both "recipient email" and "recipient user ID" are empty. Please provide one of them.',
        });
    }
    if (!(0, lodash_1.isEmpty)(value.recipientEmail) && !(0, lodash_1.isEmpty)(value.recipientUserId)) {
        context.addIssue({
            code: zod_1.z.ZodIssueCode.custom,
            fatal: true,
            message: 'Both "recipient email" and "recipient user ID" are provided. Please provide only one of them.',
        });
    }
});
//# sourceMappingURL=fields.js.map