"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePayloadAndCreateSdks = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const zod_1 = __importDefault(require("zod"));
const settings_1 = require("../settings");
const FhirR4_1 = require("./api/FhirR4");
const auth_1 = require("./api/auth");
const validatePayloadAndCreateSdks = 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 { authUrl, r4BaseUrl } = (0, auth_1.constructCernerUrls)(settings.tenantId);
    const SCOPES = [
        'system/Patient.read',
        'system/Patient.write',
        'system/Appointment.read',
        'system/DocumentReference.write',
        'system/Encounter.read',
    ];
    const cernerFhirR4Sdk = new FhirR4_1.CernerR4APIClient({
        authUrl,
        baseUrl: r4BaseUrl,
        requestConfig: {
            client_id: settings.clientId,
            client_secret: settings.clientSecret,
            scope: SCOPES.join(','),
        },
    });
    return {
        cernerFhirR4Sdk,
        settings,
        fields,
        patient,
        pathway,
        activity,
    };
};
exports.validatePayloadAndCreateSdks = validatePayloadAndCreateSdks;
//# sourceMappingURL=validatePayloadAndCreateSdks.js.map