"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const action = {
    title: 'Create Alias V2',
    description: 'Create new user aliases for existing identified users, or to create new unidentified users.',
    defaultSubscription: 'event = "Create Alias"',
    fields: {
        external_id: {
            label: 'External ID',
            description: 'The external ID of the user to create an alias for.',
            type: 'string',
            allowNull: true
        },
        alias_name: {
            label: 'Alias Name',
            description: 'The alias identifier',
            type: 'string',
            required: true
        },
        alias_label: {
            label: 'Alias Label',
            description: 'A label indicating the type of alias',
            type: 'string',
            required: true
        }
    },
    syncMode: {
        description: 'Define how the records from your destination will be synced.',
        label: 'How to add Aliases',
        default: 'add',
        choices: [{ label: 'Create Alias', value: 'add' }]
    },
    perform: (request, { settings, payload, syncMode }) => {
        if (syncMode === 'add') {
            return request(`${settings.endpoint}/users/alias/new`, {
                method: 'post',
                json: {
                    user_aliases: [
                        {
                            external_id: payload.external_id ?? undefined,
                            alias_name: payload.alias_name,
                            alias_label: payload.alias_label
                        }
                    ]
                }
            });
        }
        throw new actions_core_1.IntegrationError('syncMode must be "add"', 'Invalid syncMode', 400);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map