"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startCareFlow = 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.startCareFlow = {
    key: 'startCareFlow',
    category: extensions_core_1.Category.WORKFLOW,
    title: 'Start care flow',
    description: 'Start a new care flow for the patient currently enrolled in the care flow.',
    fields: config_1.fields,
    dataPoints: config_1.dataPoints,
    previewable: false, // We don't have pathways in Preview, only cases.
    onEvent: async ({ payload, onComplete, helpers }) => {
        const { fields: { pathwayDefinitionId, baselineInfo }, patient: { id: patientId }, } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                patient: config_1.PatientValidationSchema,
            }),
            payload,
        });
        const sdk = await helpers.awellSdk();
        const resp = await sdk.orchestration.mutation({
            startPathway: {
                __args: {
                    input: {
                        patient_id: patientId,
                        pathway_definition_id: pathwayDefinitionId,
                        data_points: baselineInfo,
                    },
                },
                pathway_id: true,
            },
        });
        const careFlowId = resp.startPathway.pathway_id;
        await onComplete({
            data_points: {
                careFlowId,
            },
            events: [
                (0, addEventLog_1.addActivityEventLog)({
                    message: `Care flow started, instance ID: ${careFlowId}.`,
                }),
            ],
        });
    },
};
//# sourceMappingURL=startCareFlow.js.map