"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sum = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const zod_1 = require("zod");
exports.sum = {
    key: 'sum',
    title: 'Sum',
    description: 'Calculate the sum of two or more addends',
    category: extensions_core_1.Category.MATH,
    fields: config_1.fields,
    dataPoints: config_1.dataPoints,
    previewable: true,
    onActivityCreated: async (payload, onComplete, onError) => {
        const { fields } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({ fields: config_1.FieldsValidationSchema }),
            payload,
        });
        const sumAddends = (fields) => {
            return Object.values(fields).reduce((acc, curr) => acc + (curr !== null && curr !== void 0 ? curr : 0), 0);
        };
        const sum = sumAddends(fields);
        await onComplete({
            data_points: {
                sum: String(sum),
            },
        });
    },
};
//# sourceMappingURL=sum.js.map