"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: 'Remove Profile from List (Engage)',
    description: 'Remove profile from list',
    defaultSubscription: 'event = "Audience Exited"',
    fields: {
        email: { ...properties_1.email },
        external_id: { ...properties_1.external_id },
        list_id: { ...properties_1.list_id },
        phone_number: { ...properties_1.phone_number },
        enable_batching: { ...properties_1.enable_batching },
        country_code: { ...properties_1.country_code },
        batch_size: { ...properties_1.batch_size, default: 1000, minimum: 100, maximum: 1000 },
        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, list_id, external_id, phone_number: initialPhoneNumber, country_code } = 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 profileIds = await (0, functions_1.getProfiles)(request, email ? [email] : undefined, external_id ? [external_id] : undefined, phone_number ? [phone_number] : undefined);
        if (!profileIds?.length) {
            throw new actions_core_1.PayloadValidationError('No profiles found for the provided identifiers.');
        }
        return await (0, functions_1.removeProfileFromList)(request, profileIds, list_id);
    },
    performBatch: async (request, { payload, statsContext }) => {
        return await (0, functions_1.removeBulkProfilesFromList)(request, payload, statsContext);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map