"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendCall = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const validatePayloadAndCreateSdk_1 = require("../../lib/validatePayloadAndCreateSdk");
const config_1 = require("./config");
const schema_1 = require("../../api/schema");
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
exports.sendCall = {
    key: 'sendCall',
    category: extensions_core_1.Category.COMMUNICATION,
    title: 'Send call',
    description: 'Send an AI phone call with a custom objective and actions.',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete }) => {
        const { fields, blandSdk } = await (0, validatePayloadAndCreateSdk_1.validatePayloadAndCreateSdk)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const sendCallInput = schema_1.SendCallInputSchema.parse({
            ...fields,
            phone_number: fields.phoneNumber,
            request_data: fields.requestData,
            metadata: {
                ...fields.metadata,
                awell_patient_id: payload.patient.id,
                awell_care_flow_definition_id: payload.pathway.definition_id,
                awell_care_flow_id: payload.pathway.id,
                awell_activity_id: payload.activity.id,
            },
            analysis_schema: fields.analysisSchema,
        });
        const { data } = await blandSdk.sendCall({
            ...sendCallInput,
        });
        await onComplete({
            data_points: {
                call_id: data.call_id,
            },
            events: [
                (0, addEventLog_1.addActivityEventLog)({
                    message: `Request for call sent to Bland.\nStatus: ${data.status}\nCall ID: ${data.call_id}\nMessage: ${data.message}`,
                }),
            ],
        });
    },
};
//# sourceMappingURL=sendCall.js.map