"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePatient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const config_1 = require("./config");
const zod_1 = require("zod");
const awellSdk_1 = __importDefault(require("../../sdk/awellSdk"));
exports.updatePatient = {
    key: 'updatePatient',
    category: extensions_core_1.Category.WORKFLOW,
    title: 'Update patient',
    description: 'Update the current patient with new data.',
    fields: config_1.fields,
    previewable: false,
    supports_automated_retries: true,
    onEvent: async ({ payload, onComplete, helpers }) => {
        const { fields: { patientCode, firstName, lastName, birthDate, email, phone, mobilePhone, street, state, country, city, zip, preferredLanguage, sex, nationalRegistryNumber, patientTimzone, }, patient: { id: patientId }, } = (0, extensions_core_1.validate)({
            schema: zod_1.z.object({
                fields: config_1.FieldsValidationSchema,
                patient: config_1.PatientValidationSchema,
            }),
            payload,
        });
        const awellSdk = await helpers.awellSdk();
        const sdk = new awellSdk_1.default({
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
            apiUrl: awellSdk.apiUrl,
            apiKey: awellSdk.apiKey,
        });
        // we cannot use this until we fully deprecate patient_code
        // await awellSdk.orchestration.mutation({
        //   updatePatient: {
        //     __args: {
        //       input: {
        //         patient_id: patientId,
        //         patient_code: patientCode,
        //         first_name: firstName,
        //         last_name: lastName,
        //         birth_date: birthDate,
        //         email,
        //         phone,
        //         mobile_phone: mobilePhone,
        //         address: {
        //           street,
        //           state,
        //           country,
        //           city,
        //           zip,
        //         },
        //         preferred_language: preferredLanguage,
        //         sex,
        //         national_registry_number: nationalRegistryNumber,
        //       },
        //     },
        //   }
        // })
        await sdk.updatePatient({
            patient_id: patientId,
            profile: {
                patient_code: patientCode,
                first_name: firstName,
                last_name: lastName,
                birth_date: birthDate,
                email,
                phone,
                mobile_phone: mobilePhone,
                address: {
                    street,
                    state,
                    country,
                    city,
                    zip,
                },
                preferred_language: preferredLanguage,
                sex,
                national_registry_number: nationalRegistryNumber,
                patient_timezone: patientTimzone,
            },
        });
        await onComplete();
    },
};
//# sourceMappingURL=updatePatient.js.map