"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUrl = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const client_1 = require("../../client");
const errorHandler_1 = require("../../shared/errorHandler");
const fields_1 = require("./fields");
const validation_1 = require("./validation");
const dataPoints_1 = require("./dataPoints");
exports.getUrl = {
    key: 'getUrl',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Get Document URL',
    description: 'Fetches the document from S3 and sends a presigned URL.',
    fields: fields_1.getUrlFields,
    previewable: true,
    dataPoints: dataPoints_1.documentUrlPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        try {
            const { fileName } = validation_1.getUrlSchema.parse(payload.fields);
            const api = (0, client_1.createMetriportApi)(payload.settings);
            const resp = await api.getDocumentUrl(fileName);
            await onComplete({
                data_points: {
                    url: resp.url,
                },
            });
        }
        catch (err) {
            await (0, errorHandler_1.handleErrorMessage)(err, onError);
        }
    },
};
//# sourceMappingURL=getUrl.js.map