"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const action = {
    title: 'Track Event',
    description: 'Record custom events in Braze',
    defaultSubscription: 'type = "track" and event != "Order Completed"',
    fields: {
        external_id: {
            label: 'External User ID',
            description: 'The unique user identifier',
            type: 'string',
            default: {
                '@path': '$.userId'
            }
        },
        user_alias: {
            label: 'User Alias Object',
            description: 'A user alias object. See [the docs](https://www.braze.com/docs/api/objects_filters/user_alias_object/).',
            type: 'object',
            properties: {
                alias_name: {
                    label: 'Alias Name',
                    type: 'string'
                },
                alias_label: {
                    label: 'Alias Label',
                    type: 'string'
                }
            }
        },
        email: {
            label: 'Email',
            description: 'The user email',
            type: 'string',
            default: {
                '@if': {
                    exists: { '@path': '$.context.traits.email' },
                    then: { '@path': '$.context.traits.email' },
                    else: { '@path': '$.properties.email' }
                }
            }
        },
        braze_id: {
            label: 'Braze User Identifier',
            description: 'The unique user identifier',
            type: 'string',
            allowNull: true,
            default: {
                '@path': '$.properties.braze_id'
            }
        },
        name: {
            label: 'Event Name',
            description: 'The event name',
            type: 'string',
            required: true,
            default: {
                '@path': '$.event'
            }
        },
        time: {
            label: 'Time',
            description: 'When the event occurred.',
            type: 'datetime',
            required: true,
            default: {
                '@path': '$.receivedAt'
            }
        },
        properties: {
            label: 'Event Properties',
            description: 'Properties of the event',
            type: 'object',
            default: {
                '@path': '$.properties'
            }
        },
        _update_existing_only: {
            label: 'Update Existing Only',
            description: 'Setting this flag to true will put the API in "Update Only" mode. When using a "user_alias", "Update Only" mode is always true.',
            type: 'boolean',
            default: false
        },
        enable_batching: {
            type: 'boolean',
            label: 'Batch Data to Braze',
            description: 'If true, Segment will batch events before sending to Braze’s user track endpoint. Braze accepts batches of up to 75 events.',
            default: true
        },
        batch_size: {
            label: 'Batch Size',
            description: 'Maximum number of events to include in each batch. Actual batch sizes may be lower.',
            type: 'number',
            default: 75,
            unsafe_hidden: true
        }
    },
    perform: (request, { settings, payload }) => {
        return (0, utils_1.sendTrackEvent)(request, settings, payload);
    },
    performBatch: (request, { settings, payload }) => {
        return (0, utils_1.sendBatchedTrackEvent)(request, settings, payload);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map