"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addMessageToThread = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../settings");
const client_1 = require("../../client");
const config_1 = require("./config");
exports.addMessageToThread = {
    key: 'addMessageToThread',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Add Message to an existing thread',
    description: 'Adds a message to an existing thread in Elation',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete, onError }) => {
        const { fields, settings } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                settings: settings_1.SettingsValidationSchema,
            }),
            payload,
        });
        const api = (0, client_1.makeAPIClient)(settings);
        const { id } = await api.addMessageToThread({
            thread: fields.threadId,
            sender: fields.senderId,
            body: fields.messageBody,
            send_date: new Date().toISOString(),
        });
        await onComplete({
            data_points: {
                messageId: String(id),
            },
        });
    },
};
//# sourceMappingURL=addMessageToThread.js.map