"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGoal = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const validatePayloadAndCreateSdk_1 = require("../../lib/sdk/validatePayloadAndCreateSdk");
exports.createGoal = {
    key: 'createGoal',
    category: extensions_core_1.Category.EHR_INTEGRATIONS,
    title: 'Create goal',
    description: 'Create a goal for a patient in Healthie',
    fields: config_1.fields,
    previewable: true,
    dataPoints: config_1.dataPoints,
    onActivityCreated: async (payload, onComplete, onError) => {
        var _a, _b;
        const { fields, healthieSdk } = await (0, validatePayloadAndCreateSdk_1.validatePayloadAndCreateSdk)({
            fieldsSchema: config_1.FieldsValidationSchema,
            payload,
        });
        const input = {
            user_id: fields.healthiePatientId,
            repeat: fields.repeat,
            title_link: fields.titleLink,
            name: fields.name,
            due_date: fields.dueDate,
        };
        const res = await healthieSdk.client.mutation({
            createGoal: {
                __args: {
                    input,
                },
                goal: {
                    id: true,
                },
            },
        });
        await onComplete({
            data_points: {
                createdGoalId: String((_b = (_a = res.createGoal) === null || _a === void 0 ? void 0 : _a.goal) === null || _b === void 0 ? void 0 : _b.id),
            },
        });
    },
};
//# sourceMappingURL=createGoal.js.map