"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fields_1 = require("../fields");
const utils_1 = require("../utils");
const sendRequest = async (request, payloads, settings) => {
    const host = utils_1.hosts[settings.region];
    const requestBody = payloads.map((payload) => {
        return {
            user_identifiers: payload.user_identifiers,
            action: payload.event_action,
            type: payload.event_type ?? 'custom',
            timestamp: payload.timestamp,
            order_id: payload.order_id,
            total: payload.total,
            products: payload.products
        };
    });
    return request(`${host}/batch_custom_event`, {
        method: 'post',
        json: requestBody
    });
};
const action = {
    title: 'Ecommerce Event',
    description: 'Send Segment Ecommerce track() events to Optimizely Data Platform',
    fields: {
        user_identifiers: fields_1.user_identifiers,
        event_type: fields_1.event_type,
        event_action: {
            label: 'Optimizely Event Action',
            description: 'The name of the Optimizely Event Action.',
            type: 'string',
            required: true
        },
        products: fields_1.products,
        order_id: fields_1.order_id,
        total: fields_1.total,
        timestamp: fields_1.timestamp,
        enable_batching: fields_1.enable_batching,
        batch_size: fields_1.batch_size
    },
    perform: (request, { payload, settings }) => {
        return sendRequest(request, [payload], settings);
    },
    performBatch: (request, { payload, settings }) => {
        return sendRequest(request, payload, settings);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map