"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const customerio_properties_1 = require("../customerio-properties");
const action = {
    title: 'Merge People',
    description: 'Merge two customer profiles together.',
    defaultSubscription: 'type = "alias"',
    fields: {
        primary: {
            label: 'Primary User',
            description: `The person that you want to remain after the merge, identified by id, email or cio_id. This person receives information from the secondary person in the merge.`,
            type: 'string',
            required: true,
            default: {
                '@path': '$.userId'
            }
        },
        secondary: {
            label: 'Secondary User',
            description: `The person that you want to delete after the merge, identified by id, email or cio_id. This person's information is merged into the primary person's profile and then it is deleted.`,
            type: 'string',
            required: true,
            default: {
                '@path': '$.previousId'
            }
        },
        ...customerio_properties_1.eventProperties
    },
    performBatch: (request, { payload: payloads, settings }) => {
        return (0, utils_1.sendBatch)(request, payloads.map((payload) => ({
            action: 'merge',
            payload: mapPayload(payload),
            settings,
            type: 'person'
        })));
    },
    perform: (request, { payload, settings }) => {
        return (0, utils_1.sendSingle)(request, {
            action: 'merge',
            payload: mapPayload(payload),
            settings,
            type: 'person'
        });
    }
};
function mapPayload(payload) {
    return {
        primary: (0, utils_1.resolveIdentifiers)({ person_id: payload.primary }),
        secondary: (0, utils_1.resolveIdentifiers)({ person_id: payload.secondary })
    };
}
exports.default = action;
//# sourceMappingURL=index.js.map