"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLead = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const lib_1 = require("../../lib");
const errors_1 = require("../../lib/errors");
exports.getLead = {
    key: 'getLead',
    category: extensions_core_1.Category.CUSTOMER_SUPPORT,
    title: 'Get lead',
    description: 'Retrieve a Lead from Salesforce',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete, onError, helpers }) => {
        const { fields, salesforceClient } = await (0, lib_1.validatePayloadAndCreateClient)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        try {
            const res = await salesforceClient.getRecord({
                sObject: 'Lead',
                sObjectId: fields.leadId,
            });
            await onComplete({
                data_points: {
                    leadData: JSON.stringify(res),
                },
            });
        }
        catch (error) {
            if ((0, errors_1.isSalesforceError)(error)) {
                await onError({
                    events: [(0, errors_1.parseSalesforceError)(error)],
                });
            }
            else {
                // we handle ZodError and unknown errors in extension-server directly
                throw error;
            }
        }
    },
};
//# sourceMappingURL=getLead.js.map