"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 api_client_1 = require("@hubspot/api-client");
const smtpApi_1 = require("./smtpApi");
const lodash_1 = require("lodash");
const validatePayloadAndCreateSdks = async ({ fieldsSchema, payload }) => {
    const { settings: { accessToken, smtpPassword, smtpUsername }, fields, settings, } = (0, extensions_core_1.validate)({
        schema: zod_1.default.object({
            fields: fieldsSchema,
            settings: settings_1.SettingsValidationSchema,
        }),
        payload,
    });
    const { patient, pathway, activity } = payload;
    const hubSpotSdk = new api_client_1.Client({
        accessToken,
    });
    const getSmptClient = () => {
        if ((0, lodash_1.isEmpty)(smtpPassword) || (0, lodash_1.isEmpty)(smtpUsername)) {
            return undefined;
        }
        return new smtpApi_1.HubSpotSMTPClient({
            username: smtpUsername,
            password: smtpPassword,
        });
    };
    const hubSpotSmtpSdk = getSmptClient();
    return {
        hubSpotSdk,
        hubSpotSmtpSdk,
        fields,
        settings,
        patient,
        pathway,
        activity,
    };
};
exports.validatePayloadAndCreateSdks = validatePayloadAndCreateSdks;
//# sourceMappingURL=validatePayloadAndCreateSdk.js.map