"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendEmail = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../../settings");
const config_1 = require("./config");
const client_1 = require("../../client");
exports.sendEmail = {
    key: 'sendEmail',
    title: 'Send email',
    description: 'Send an email to a specific email address.',
    category: extensions_core_1.Category.COMMUNICATION,
    fields: config_1.fields,
    previewable: true,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { settings: { apiKey }, fields: { campaignId, recipientEmail, recipientUserId, dataFields, allowRepeatMarketingSends, metadata, }, } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                settings: settings_1.SettingsValidationSchema,
                fields: config_1.FieldsValidationSchema,
            }),
            payload,
        });
        const client = new client_1.IterableClient({
            apiKey,
        });
        await client.emailApi.sendEmail({
            campaignId,
            recipientEmail,
            recipientUserId,
            dataFields,
            allowRepeatMarketingSends,
            metadata,
        });
        await onComplete();
    },
};
//# sourceMappingURL=sendEmail.js.map