"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePayloadAndCreateSdk = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const zod_1 = __importDefault(require("zod"));
const settings_1 = require("../../settings");
const healthie_sdk_1 = require("@awell-health/healthie-sdk");
const sdk_1 = require("./graphql-codegen/generated/sdk");
const graphqlClient_1 = require("./graphql-codegen/graphqlClient");
const validatePayloadAndCreateSdk = async ({ fieldsSchema, payload, }) => {
    const { settings, fields } = (0, extensions_core_1.validate)({
        schema: zod_1.default.object({
            fields: fieldsSchema,
            settings: settings_1.SettingsValidationSchema,
        }),
        payload,
    });
    const { patient, pathway, activity } = payload;
    const client = (0, graphqlClient_1.initialiseClient)(settings);
    if (client === undefined)
        throw new Error('Healthie client cannot be undefined.');
    /**
     * Old sdk, generated with graphql-codegen
     */
    const deprecatedSdk = (0, sdk_1.getSdk)(client);
    /**
     * New sdk, generated with GenQL
     */
    const healthieSdk = new healthie_sdk_1.HealthieSdk(settings);
    return {
        settings,
        fields,
        sdk: deprecatedSdk,
        healthieSdk,
        patient,
        pathway,
        activity,
    };
};
exports.validatePayloadAndCreateSdk = validatePayloadAndCreateSdk;
//# sourceMappingURL=validatePayloadAndCreateSdk.js.map