"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tablemaintutilities_1 = require("../Utility/tablemaintutilities");
const get_1 = __importDefault(require("lodash/get"));
const eventprocessing_1 = require("../Utility/eventprocessing");
const action = {
    title: 'Receive Track and Identify Events',
    description: 'Provide Segment Track and Identify Event Data to Acoustic Campaign',
    fields: {
        email: {
            label: 'Email',
            description: 'At a minimum Email is required, see mapping presets for more info.',
            type: 'string',
            format: 'email',
            required: true,
            default: {
                '@path': '$.email'
            }
        },
        type: {
            label: 'Type',
            description: 'The Event Type, will be either Track or Identify',
            type: 'string',
            default: {
                '@path': '$.type'
            }
        },
        timestamp: {
            label: 'Timestamp',
            description: 'The Timestamp of the Event',
            type: 'datetime',
            default: {
                '@path': '$.timestamp'
            }
        },
        key_value_pairs: {
            label: 'Key-Value pairs',
            description: 'Map simple Key-Value pairs of Event data here.',
            type: 'object'
        },
        array_data: {
            label: 'Arrays',
            description: 'Map Arrays of data into flattened data attributes here.',
            type: 'object',
            multiple: true,
            additionalProperties: true
        },
        context: {
            label: 'Context',
            description: 'All properties provided via a Context Section ',
            type: 'object'
        },
        properties: {
            label: 'Properties',
            description: 'All properties provided via a Properties Section',
            type: 'object'
        },
        traits: {
            label: 'Traits',
            description: 'All properties provided via a Traits Section',
            type: 'object'
        }
    },
    perform: async (request, { settings, payload, auth }) => {
        const email = (0, get_1.default)(payload, 'email', '');
        const rows = (0, eventprocessing_1.addUpdateEvents)(payload, email, settings.attributesMax);
        let a_Auth = {};
        if (!auth?.accessToken)
            a_Auth = (0, tablemaintutilities_1.getAuthCreds)();
        const POSTUpdates = `<Envelope>
      <Body>
        <InsertUpdateRelationalTable>
        <TABLE_ID>${settings.tableListId} </TABLE_ID>
          <ROWS>${rows}</ROWS>
        </InsertUpdateRelationalTable>
      </Body>
    </Envelope>`;
        return await (0, tablemaintutilities_1.doPOST)(request, settings, auth ?? a_Auth, POSTUpdates, 'POST_Updates');
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map