"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const functions_1 = require("../functions");
const properties_1 = require("../properties");
const api_1 = require("../api");
const action = {
    title: 'Remove Users (Legacy)',
    description: 'Remove contacts from an Engage Audience to a TikTok Audience Segment.',
    defaultSubscription: 'event = "Audience Exited"',
    fields: {
        selected_advertiser_id: { ...properties_1.selected_advertiser_id },
        audience_id: { ...properties_1.audience_id },
        email: { ...properties_1.email },
        phone: { ...properties_1.phone },
        advertising_id: { ...properties_1.advertising_id },
        send_email: { ...properties_1.send_email },
        send_phone: { ...properties_1.send_phone },
        send_advertising_id: { ...properties_1.send_advertising_id },
        event_name: { ...properties_1.event_name },
        enable_batching: { ...properties_1.enable_batching }
    },
    dynamicFields: {
        selected_advertiser_id: async (request, { settings }) => {
            try {
                const tiktok = new api_1.TikTokAudiences(request);
                if (settings.advertiser_ids) {
                    return tiktok.fetchAdvertisers(settings.advertiser_ids);
                }
                return {
                    choices: [],
                    error: {
                        message: JSON.stringify('BAD REQUEST - expected settings.advertiser_ids and got nothing!'),
                        code: '400'
                    }
                };
            }
            catch (err) {
                return {
                    choices: [],
                    error: {
                        message: JSON.stringify(err),
                        code: '500'
                    }
                };
            }
        },
        audience_id: async (request, { payload }) => {
            try {
                const tiktok = new api_1.TikTokAudiences(request);
                return await tiktok.fetchAudiences(payload.selected_advertiser_id);
            }
            catch (err) {
                return {
                    choices: [],
                    error: {
                        message: JSON.stringify(err),
                        code: '500'
                    }
                };
            }
        }
    },
    perform: async (request, { settings, payload, statsContext }) => {
        statsContext?.statsClient?.incr('removeUserLegacy', 1, statsContext?.tags);
        return (0, functions_1.processPayload)(request, settings, [payload], 'delete');
    },
    performBatch: async (request, { settings, payload, statsContext }) => {
        statsContext?.statsClient?.incr('removeUserLegacy', 1, statsContext?.tags);
        return (0, functions_1.processPayload)(request, settings, payload, 'delete');
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map