"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stopActiveCall = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const validatePayloadAndCreateSdk_1 = require("../../lib/validatePayloadAndCreateSdk");
const config_1 = require("./config");
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
exports.stopActiveCall = {
    key: 'stopActiveCall',
    category: extensions_core_1.Category.COMMUNICATION,
    title: 'Stop active call',
    description: 'End an active phone call by call ID.',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    supports_automated_retries: true,
    onEvent: async ({ payload, onComplete, helpers: { log } }) => {
        const { fields, blandSdk } = await (0, validatePayloadAndCreateSdk_1.validatePayloadAndCreateSdk)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const { data } = await blandSdk.stopActiveCall({
            call_id: fields.callId,
        });
        await onComplete({
            data_points: {
                status: data.status,
                message: data.message,
            },
            events: [
                (0, addEventLog_1.addActivityEventLog)({
                    message: `Stop call request sent to Bland.\nStatus: ${data.status}\nMessage: ${data.message}`,
                }),
            ],
        });
    },
};
//# sourceMappingURL=stopActiveCall.js.map