"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addAdhocTrack = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const zod_1 = require("zod");
const addEventLog_1 = require("../../../../../src/lib/awell/addEventLog");
exports.addAdhocTrack = {
    key: 'addAdhocTrack',
    category: extensions_core_1.Category.WORKFLOW,
    title: 'Add ad hoc track',
    description: 'Add a pre-configured ad hoc track to a patient care flow.',
    fields: config_1.fields,
    previewable: false,
    supports_automated_retries: true,
    onEvent: async ({ payload, onComplete, helpers }) => {
        const { fields: { trackId }, pathway: { id: pathwayId }, } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                pathway: config_1.PathwayValidationSchema,
            }),
            payload,
        });
        const awellSdk = await helpers.awellSdk();
        await awellSdk.orchestration.mutation({
            addTrack: {
                __args: {
                    input: {
                        track_id: trackId,
                        pathway_id: pathwayId,
                    },
                },
                code: true,
                success: true,
            },
        });
        await onComplete({
            events: [
                (0, addEventLog_1.addActivityEventLog)({
                    message: `Ad hoc track successfully added to care flow.`,
                }),
            ],
        });
    },
};
//# sourceMappingURL=addAdhocTrack.js.map