"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.trackEvent = 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.trackEvent = {
    key: 'trackEvent',
    title: 'Track event',
    description: 'Track an event in Iterable',
    category: extensions_core_1.Category.COMMUNICATION,
    fields: config_1.fields,
    previewable: true,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { settings: { apiKey }, fields: { eventName, email, userId, dataFields }, } = (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.eventsApi.trackEvent({
            eventName,
            email,
            userId,
            dataFields,
        });
        await onComplete();
    },
};
//# sourceMappingURL=trackEvent.js.map