"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const action = {
    title: 'Send Email Event',
    description: 'Send an email event to Actable for prediction. Use this to supply clicks, opens, and unsubscribes.',
    fields: {
        customer_id: {
            label: 'Customer ID',
            description: 'The unique user identifier.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.userId'
            }
        },
        date_email_sent: {
            type: "datetime",
            label: "timestamp of event",
            description: "Timestamp of event",
            required: true,
            default: {
                '@path': '$.timestamp'
            }
        },
        campaign_name: {
            type: "string",
            label: "Campaign Name of Email",
            description: "name of the campaign associated with the email",
            required: false,
            default: {
                '@path': '$.context.campaign.name'
            }
        },
        clicked_flag: {
            type: "integer",
            label: "Click Event Indicator",
            description: "1=email was clicked, 0 email was not clicked",
            required: false
        },
        opened_flag: {
            type: "integer",
            label: "Open Event Indicator",
            description: "1=email was opened, 0 email was not opened",
            required: false
        },
        unsub_flag: {
            type: "integer",
            label: "Unsubscribe Event Indicator",
            description: "1=customer unsubscribed from the email list, 0 user remained subscribed",
            required: false
        },
        stream_key: {
            type: "string",
            label: "Stream Key",
            description: "Dataset label, should be left as default unless directed otherwise",
            required: true,
            default: "email"
        }
    },
    perform: (request, data) => {
        data.payload.date_email_sent = (0, index_1.formatTimestampAsUnixSeconds)(data.payload.date_email_sent);
        return request(index_1.API_URL, {
            method: 'post',
            json: { data: [data.payload] }
        });
    },
    performBatch: (request, data) => {
        for (const ev of data.payload) {
            ev.date_email_sent = (0, index_1.formatTimestampAsUnixSeconds)(ev.date_email_sent);
        }
        return request(index_1.API_URL, {
            method: 'post',
            json: { data: data.payload }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map