"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 apiConfig_1 = require("../api/apiConfig");
const talkdeskClient_1 = require("../api/talkdeskClient");
const settings_1 = require("../settings");
const validatePayloadAndCreateClient = async ({ fieldsSchema, payload, }) => {
    const { settings: { clientId, clientSecret, region, talkDeskAccountName }, fields, settings, } = (0, extensions_core_1.validate)({
        schema: zod_1.default.object({
            fields: fieldsSchema,
            settings: settings_1.SettingsValidationSchema,
        }),
        payload,
    });
    const client = new talkdeskClient_1.TalkdeskAPIClient({
        authUrl: (0, apiConfig_1.getAuthUrl)(region, talkDeskAccountName),
        requestConfig: {
            client_id: clientId,
            client_secret: clientSecret,
            scope: apiConfig_1.scope,
        },
        baseUrl: apiConfig_1.baseURLs[region],
    });
    return { client, fields, settings };
};
exports.validatePayloadAndCreateClient = validatePayloadAndCreateClient;
//# sourceMappingURL=validatePayloadAndCreateClient.js.map