"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const customerio_properties_1 = require("../customerio-properties");
const action = {
    title: 'Report Content Event',
    description: 'Report a Viewed or Clicked Content event.',
    defaultSubscription: 'event = "Report Content Event"',
    fields: {
        anonymous_id: {
            label: 'Anonymous ID',
            description: 'ID for the anonymous user.',
            type: 'string',
            default: {
                '@path': '$.anonymousId'
            }
        },
        actionType: {
            label: 'Action Type',
            description: 'The type of content event.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.properties.actionType'
            },
            choices: [
                { label: 'Viewed', value: 'viewed_content' },
                { label: 'Clicked', value: 'clicked_content' }
            ]
        },
        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: payload.actionType,
            payload: mapPayload(payload),
            settings,
            type: 'person'
        })));
    },
    perform: (request, { payload, settings }) => {
        return (0, utils_1.sendSingle)(request, { action: payload.actionType, payload: mapPayload(payload), settings, type: 'person' });
    }
};
function mapPayload(payload) {
    const { actionType, data, ...rest } = payload;
    if (data?.actionType) {
        delete data.actionType;
    }
    return {
        ...rest,
        name: actionType,
        attributes: data
    };
}
exports.default = action;
//# sourceMappingURL=index.js.map