"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePayloadAndCreateClient = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const zod_1 = __importDefault(require("zod"));
const client_1 = require("../api/client");
const dock_types_1 = require("./dock.types");
const validatePayloadAndCreateClient = async ({ fieldsSchema, payload, }) => {
    const { settings: { environment, clientId, clientSecret, apiKey, organizationId, userId, }, pathway: { id: pathwayId }, activity: { id: activityId }, fields, settings, } = (0, extensions_core_1.validate)({
        schema: zod_1.default.object({
            fields: fieldsSchema,
            settings: dock_types_1.DockSettingsSchema,
            pathway: zod_1.default.object({ id: zod_1.default.string() }),
            activity: zod_1.default.object({ id: zod_1.default.string() }),
        }),
        payload,
    });
    const dockClient = new client_1.DockAPIClient({
        authUrl: dock_types_1.AUTH_URLS[environment],
        baseUrl: dock_types_1.API_URLS[environment],
        requestConfig: {
            client_id: clientId,
            client_secret: clientSecret,
            scope: dock_types_1.DockApiScopes,
        },
        apiKey,
        organizationId,
        userId,
    });
    return { dockClient, fields, settings, pathwayId, activityId };
};
exports.validatePayloadAndCreateClient = validatePayloadAndCreateClient;
//# sourceMappingURL=validatePayloadAndCreateClient.js.map