"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCallDetails = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const validatePayloadAndCreateSdk_1 = require("../../lib/validatePayloadAndCreateSdk");
const config_1 = require("./config");
exports.getCallDetails = {
    key: 'getCallDetails',
    category: extensions_core_1.Category.COMMUNICATION,
    title: 'Get call details',
    description: 'Retrieve detailed information, metadata and transcripts for a call.',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete }) => {
        const { fields, blandSdk } = await (0, validatePayloadAndCreateSdk_1.validatePayloadAndCreateSdk)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const { data } = await blandSdk.getCallDetails({
            call_id: fields.callId,
        });
        await onComplete({
            data_points: {
                callData: (0, lodash_1.isNil)(data) ? undefined : JSON.stringify(data),
                callLength: (0, lodash_1.isNil)(data.call_length)
                    ? undefined
                    : data.call_length.toString(),
                to: data.to,
                from: data.from,
                completed: String(data.completed),
                metadata: (0, lodash_1.isNil)(data.metadata)
                    ? undefined
                    : JSON.stringify(data.metadata),
                summary: data.summary,
                startedAt: data.started_at,
                endAt: data.end_at,
                analysisSchema: (0, lodash_1.isNil)(data.analysis_schema)
                    ? undefined
                    : JSON.stringify(data.analysis_schema),
                analysis: (0, lodash_1.isNil)(data.analysis)
                    ? undefined
                    : JSON.stringify(data.analysis),
                concatenatedTranscript: data.concatenated_transcript,
                transcripts: (0, lodash_1.isNil)(data.transcripts)
                    ? undefined
                    : JSON.stringify(data.transcripts),
                status: data.status,
            },
        });
    },
};
//# sourceMappingURL=getCallDetails.js.map