"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.callCompleted = void 0;
const lodash_1 = require("lodash");
const dataPoints = {
    callId: {
        key: 'callId',
        valueType: 'string',
    },
    callObject: {
        key: 'callObject',
        valueType: 'json',
    },
};
exports.callCompleted = {
    key: 'callCompleted',
    dataPoints,
    onEvent: async ({ payload: { payload, rawBody, headers, settings }, onSuccess, onError, }) => {
        var _a, _b;
        const callId = payload === null || payload === void 0 ? void 0 : payload.call_id;
        const awellPatientId = (_b = (_a = payload === null || payload === void 0 ? void 0 : payload.variables) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.awell_patient_id;
        if ((0, lodash_1.isNil)(callId)) {
            await onError({
                response: {
                    statusCode: 400,
                    message: 'Missing call_id in payload',
                },
            });
        }
        await onSuccess({
            data_points: {
                callId,
                callObject: JSON.stringify(payload),
            },
            ...(awellPatientId !== undefined && { patient_id: awellPatientId }),
        });
    },
};
//# sourceMappingURL=callCompleted.js.map