"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
const customerio_properties_1 = require("../customerio-properties");
const action = {
    title: 'Delete Relationship',
    description: `Delete a relationship between a person and an object in Customer.io.`,
    defaultSubscription: 'event = "Relationship Deleted"',
    fields: {
        person_id: {
            label: 'Person ID',
            description: 'The ID of the person that this mobile device belongs to.',
            type: 'string',
            required: true,
            default: {
                '@path': '$.userId'
            }
        },
        anonymous_id: {
            label: 'Anonymous ID',
            description: 'An optional anonymous ID. This is used to tie anonymous events to this person. [Learn more](https://customer.io/docs/anonymous-events/).',
            type: 'string',
            default: {
                '@path': '$.anonymousId'
            }
        },
        object_id: {
            label: 'Object ID',
            description: 'An object ID used to identify an object.',
            type: 'string',
            default: {
                '@path': '$.properties.objectId'
            },
            required: true
        },
        object_type_id: {
            label: 'Object Type ID',
            description: 'An object ID type used to identify the type of object.',
            type: 'string',
            default: {
                '@if': {
                    exists: { '@path': '$.properties.object_type_id' },
                    then: { '@path': '$.properties.object_type_id' },
                    else: { '@path': '$.properties.objectTypeId' }
                }
            }
        },
        ...customerio_properties_1.eventProperties
    },
    performBatch: (request, { payload: payloads, settings }) => {
        return (0, utils_1.sendBatch)(request, payloads.map((payload) => ({
            action: 'delete_relationships',
            settings,
            ...mapPayload(payload)
        })));
    },
    perform: (request, { payload, settings }) => {
        return (0, utils_1.sendSingle)(request, {
            action: 'delete_relationships',
            settings,
            ...mapPayload(payload)
        });
    }
};
function mapPayload(payload) {
    const { anonymous_id, person_id } = payload;
    return {
        type: 'object',
        payload: {
            ...payload,
            cio_relationships: [
                {
                    identifiers: (0, utils_1.resolveIdentifiers)({ anonymous_id, person_id })
                }
            ]
        }
    };
}
exports.default = action;
//# sourceMappingURL=index.js.map