"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_shared_1 = require("@segment/actions-shared");
const input_fields_1 = require("../input-fields");
const action = {
    title: 'Remove Contact from List',
    description: 'Removes a Contact from a List.',
    defaultSubscription: 'type = "track" and event = "Remove Contact from List"',
    fields: {
        channelIdentifier: input_fields_1.channelIdentifier,
        emailIdentifier: input_fields_1.emailIdentifier,
        mobileNumberIdentifier: input_fields_1.mobileNumberIdentifier,
        listId: {
            label: 'List',
            description: `The List to remove the Contact from.`,
            type: 'number',
            required: true,
            disabledInputMethods: ['literal', 'variable', 'function', 'freeform', 'enrichment'],
            dynamic: true
        }
    },
    dynamicFields: {
        listId: async (request, { settings }) => {
            return new actions_shared_1.DDListsApi(settings.api_host, request).getLists();
        }
    },
    perform: async (request, { settings, payload }) => {
        const { channelIdentifier, emailIdentifier, mobileNumberIdentifier, listId } = payload;
        const identifierValue = channelIdentifier === 'email' ? emailIdentifier : mobileNumberIdentifier;
        const contact = new actions_shared_1.DDContactApi(settings.api_host, request);
        const response = await contact.getContact(channelIdentifier, identifierValue);
        const lists = new actions_shared_1.DDListsApi(settings.api_host, request);
        return lists.deleteContactFromList(listId, response.contactId);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map