"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const customerio_properties_1 = require("../customerio-properties");
const action = {
    title: 'Track Event',
    description: 'Track an event for a known or anonymous person.',
    defaultSubscription: `
    type = "track"
    and event != "Application Installed"
    and event != "Application Opened"
    and event != "Application Uninstalled"
    and event != "Device Created or Updated"
    and event != "Device Deleted"
    and event != "Relationship Deleted"
    and event != "User Deleted"
    and event != "User Suppressed"
    and event != "User Unsuppressed"
    and event != "Object Deleted"
    and event != "Report Delivery Event"
    and event != "Report Content Event"
  `,
    fields: {
        id: {
            label: 'Person ID',
            description: 'The ID used to uniquely identify a person in Customer.io. [Learn more](https://customer.io/docs/identifying-people/#identifiers).',
            type: 'string',
            default: {
                '@path': '$.userId'
            }
        },
        anonymous_id: {
            label: 'Anonymous ID',
            description: 'An anonymous ID for when no Person ID exists. [Learn more](https://customer.io/docs/anonymous-events/).',
            type: 'string',
            default: {
                '@path': '$.anonymousId'
            }
        },
        name: {
            label: 'Event Name',
            description: 'The name of the event.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.event'
            }
        },
        event_id: {
            label: 'Event ID',
            description: 'An optional identifier used to deduplicate events. [Learn more](https://customer.io/docs/api/#operation/track).',
            type: 'string',
            default: {
                '@path': '$.messageId'
            }
        },
        timestamp: {
            label: 'Timestamp',
            description: 'A timestamp of when the event took place. Default is current date and time.',
            type: 'string',
            default: {
                '@path': '$.timestamp'
            }
        },
        data: {
            label: 'Event Attributes',
            description: 'Optional data to include with the event.',
            type: 'object',
            default: {
                '@path': '$.properties'
            }
        },
        convert_timestamp: {
            label: 'Convert Timestamps',
            description: 'Convert dates to Unix timestamps (seconds since Epoch).',
            type: 'boolean',
            default: true
        },
        ...customerio_properties_1.eventProperties
    },
    performBatch: (request, { payload: payloads, settings }) => {
        return (0, utils_1.sendBatch)(request, payloads.map((payload) => ({ action: 'event', payload: mapPayload(payload), settings, type: 'person' })));
    },
    perform: (request, { payload, settings }) => {
        return (0, utils_1.sendSingle)(request, { action: 'event', payload: mapPayload(payload), settings, type: 'person' });
    }
};
function mapPayload(payload) {
    const { id, event_id, data, ...rest } = payload;
    return {
        ...rest,
        person_id: id,
        id: event_id,
        attributes: data
    };
}
exports.default = action;
//# sourceMappingURL=index.js.map