"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const functions_1 = require("../functions");
const properties_1 = require("../properties");
const action = {
    title: 'Add Profile to List',
    description: 'Add Profile To List',
    defaultSubscription: 'event = "Audience Entered"',
    fields: {
        email: { ...properties_1.email },
        phone_number: { ...properties_1.phone_number },
        list_id: { ...properties_1.list_id },
        external_id: { ...properties_1.external_id },
        enable_batching: { ...properties_1.enable_batching },
        batch_size: { ...properties_1.batch_size, default: 10000, minimum: 100, maximum: 10000 },
        first_name: { ...properties_1.first_name },
        last_name: { ...properties_1.last_name },
        image: { ...properties_1.image },
        title: { ...properties_1.title },
        organization: { ...properties_1.organization },
        location: { ...properties_1.location },
        properties: { ...properties_1.properties },
        country_code: { ...properties_1.country_code },
        batch_keys: {
            label: 'Batch Keys',
            description: 'The keys to use for batching the events.',
            type: 'string',
            unsafe_hidden: true,
            required: false,
            multiple: true,
            default: ['list_id']
        }
    },
    perform: async (request, { payload }) => {
        const { email, phone_number: initialPhoneNumber, list_id, external_id, enable_batching, batch_size, country_code, batch_keys, ...additionalAttributes } = payload;
        const phone_number = (0, functions_1.processPhoneNumber)(initialPhoneNumber, country_code);
        if (!email && !external_id && !phone_number) {
            throw new actions_core_1.PayloadValidationError('One of External ID, Phone Number and Email is required.');
        }
        const profileId = await (0, functions_1.createProfile)(request, email, external_id, phone_number, additionalAttributes);
        return await (0, functions_1.addProfileToList)(request, profileId, list_id);
    },
    performBatch: async (request, { payload, statsContext }) => {
        return (0, functions_1.sendBatchedProfileImportJobRequest)(request, payload, statsContext);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map