"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptimizelyClient = void 0;
const utils_1 = require("../utils");
class OptimizelyClient {
    constructor(request, data) {
        this.request = request;
        this.settings = data.settings;
        this.payloads = Array.isArray(data.payload) ? data.payload : [data.payload];
        this.propsOrTraits = Array.isArray(data.rawData) ? data.rawData : [data.rawData];
    }
    async send() {
        const host = (0, utils_1.getHost)(this.settings);
        const requestBody = this.payloads.map((payload, index) => {
            return {
                audienceId: payload.segment_computation_id,
                audienceName: payload.custom_audience_name,
                timestamp: payload.timestamp,
                subscription: this.propsOrTraits[index].properties?.[payload.custom_audience_name] ??
                    this.propsOrTraits[index].traits?.[payload.custom_audience_name],
                userId: payload.optimizelyUserId
            };
        });
        return this.request(`${host}/batch_sync_audience`, {
            method: 'post',
            json: requestBody
        });
    }
}
exports.OptimizelyClient = OptimizelyClient;
//# sourceMappingURL=optimizely-client.js.map