"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadSingleFile = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const settings_1 = require("../../settings");
const config_1 = require("./config");
const zod_validation_error_1 = require("zod-validation-error");
const zod_1 = require("zod");
exports.uploadSingleFile = {
    key: 'uploadSingleFile',
    title: 'Upload single file',
    description: 'Allow a stakeholder to upload one file',
    category: extensions_core_1.Category.CONTENT_AND_FILES,
    fields: config_1.fields,
    options: {
        stakeholders: {
            label: 'Stakeholder',
            mode: 'single',
        },
    },
    dataPoints: config_1.dataPoints,
    previewable: false, // We don't have Awell Hosted Pages in Preview so cannot be previewed.
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            (0, extensions_core_1.validate)({
                schema: zod_1.z.object({
                    settings: settings_1.SettingsValidationSchema,
                    fields: config_1.FieldsValidationSchema,
                }),
                payload,
            });
            /**
             * Completion happens in Awell Hosted Pages
             */
        }
        catch (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 orchestration the action' },
                        error: {
                            category: 'SERVER_ERROR',
                            message: error.message,
                        },
                    },
                ],
            });
        }
    },
};
//# sourceMappingURL=uploadSingleFile.js.map