"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../api");
const input_fields_1 = require("../input-fields");
const action = {
    title: 'Add Contact to List',
    description: 'Adds a contact to a list.',
    defaultSubscription: 'type = "track" and event = "Add Contact to List"',
    fields: {
        ...input_fields_1.contactIdentifier,
        listId: {
            label: 'List',
            description: `The list to add the contact to.`,
            type: 'number',
            required: true,
            allowNull: false,
            disabledInputMethods: ['literal', 'variable', 'function', 'freeform', 'enrichment'],
            dynamic: true
        },
        dataFields: {
            label: 'Data Fields',
            description: `An object containing key/value pairs for data fields assigned to this Contact. Custom Data Fields must already be defined in Dotdigital.`,
            type: 'object',
            required: false,
            disabledInputMethods: ['literal', 'variable', 'function', 'freeform', 'enrichment'],
            defaultObjectUI: 'keyvalue:only',
            additionalProperties: false,
            dynamic: true
        }
    },
    dynamicFields: {
        listId: async (request, { settings }) => {
            return new api_1.DDListsApi(settings, request).getLists();
        },
        dataFields: {
            __keys__: async (request, { settings }) => {
                return new api_1.DDDataFieldsApi(settings, request).getDataFields();
            }
        }
    },
    perform: async (request, { settings, payload }) => {
        const fieldsAPI = new api_1.DDDataFieldsApi(settings, request);
        await fieldsAPI.validateDataFields(payload);
        const contactApi = new api_1.DDContactApi(settings, request);
        return contactApi.upsertContact(payload);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map