"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.failoWorld = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const extensions_core_2 = require("@awell-health/extensions-core");
const fields = {
    failureAttempts: {
        id: 'failureAttempts',
        label: 'Number of attempts that should fail',
        description: 'Specify how many attempts should fail before the action succeeds',
        type: extensions_core_1.FieldType.NUMERIC,
        required: true,
    },
};
const dataPoints = {
    currentAttempt: {
        key: 'currentAttempt',
        valueType: 'number',
    },
    result: {
        key: 'result',
        valueType: 'string',
    },
};
exports.failoWorld = {
    key: 'test-retry',
    category: extensions_core_2.Category.DEMO,
    title: 'Fail-o World',
    description: 'A test action that fails for a specified number of attempts to test the automated retry mechanism.',
    fields,
    previewable: false,
    supports_automated_retries: true,
    dataPoints,
    onEvent: async ({ payload, onComplete, onError, attempt }) => {
        const { fields } = payload;
        const failureAttempts = Number(fields.failureAttempts);
        if (attempt <= failureAttempts) {
            // This attempt should fail
            await onError({
                events: [
                    {
                        date: new Date().toISOString(),
                        text: {
                            en: `Attempt ${attempt} of ${failureAttempts} - Intentionally failing for testing retry mechanism`,
                        },
                        error: {
                            category: 'SERVER_ERROR',
                            message: `This is intentional failure #${attempt}`,
                        },
                    },
                ],
            });
            return;
        }
        // This attempt should succeed
        await onComplete({
            data_points: {
                currentAttempt: String(attempt),
                result: `Success on attempt ${attempt} after ${failureAttempts} failures`,
            },
        });
    },
};
//# sourceMappingURL=failoWorld.js.map