"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayTest = void 0;
const config_1 = require("./config");
const extensions_core_1 = require("@awell-health/extensions-core");
const fields_1 = require("./config/fields");
const zod_validation_error_1 = require("zod-validation-error");
const zod_1 = require("zod");
exports.arrayTest = {
    key: 'arrayTest',
    title: 'Array fields test',
    description: 'Just to show string and numeric array fields',
    category: extensions_core_1.Category.DEMO,
    fields: config_1.fields,
    dataPoints: config_1.dataPoints,
    previewable: true,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const { stringArray, anotherStringArray, numericArray, anotherNumericArray, } = (0, fields_1.validateActionFields)(payload.fields);
            const strings = [...stringArray, ...anotherStringArray];
            console.log('🚀 ~ onActivityCreated: ~ strings:', strings);
            const numbers = [...numericArray, ...anotherNumericArray];
            console.log('🚀 ~ onActivityCreated: ~ numbers:', numbers);
            await onComplete({
                data_points: {
                    allStrings: JSON.stringify(strings),
                    allNumbers: JSON.stringify(numbers),
                },
            });
        }
        catch (err) {
            console.log('error', err);
            if (err instanceof zod_1.ZodError) {
                const error = (0, zod_validation_error_1.fromZodError)(err);
                await onError({
                    events: [
                        {
                            date: new Date().toISOString(),
                            text: { en: error.name },
                            error: {
                                category: 'WRONG_INPUT',
                                message: `${error.message}`,
                            },
                        },
                    ],
                });
                return;
            }
            const error = err;
            await onError({
                events: [
                    {
                        date: new Date().toISOString(),
                        text: { en: 'Something went wrong while orchestrating the action' },
                        error: {
                            category: 'SERVER_ERROR',
                            message: error.message,
                        },
                    },
                ],
            });
        }
    },
};
//# sourceMappingURL=arrayTest.js.map