"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stopCareFlow = 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.stopCareFlow = {
    key: 'stopCareFlow',
    category: extensions_core_1.Category.WORKFLOW,
    title: 'Stop care flow',
    description: 'Stop the care flow the patient is currently enrolled.',
    fields: config_1.fields,
    previewable: false, // We don't have pathways in Preview, only cases.
    onEvent: async ({ payload, onComplete, helpers }) => {
        const { fields: { reason }, 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({
            stopPathway: {
                __args: {
                    input: {
                        pathway_id: pathwayId,
                        reason,
                    },
                },
                code: true,
                success: true,
            },
        });
        await onComplete({
            events: [
                (0, addEventLog_1.addActivityEventLog)({
                    message: `Care flow successfully stopped.`,
                }),
            ],
        });
    },
};
//# sourceMappingURL=stopCareFlow.js.map