"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncAudience = syncAudience;
const constants_1 = require("./constants");
async function syncAudience(request, payloads, settings) {
    const { audience_id, audience_name } = payloads[0];
    const { advertiserId } = settings;
    const addEmails = [];
    const removeEmails = [];
    payloads.forEach((payload) => {
        const action = payload.traits_or_props[payload.audience_name];
        const profileDetails = payload.personal_information ?? undefined;
        const ip_address = payload.ip_address ?? undefined;
        if (action) {
            addEmails.push({ email: payload.email, ip_address, profileDetails });
        }
        else {
            removeEmails.push({ email: payload.email, ip_address, profileDetails });
        }
    });
    const json = {
        advertiserId,
        audienceId: audience_id,
        audienceName: audience_name,
        addProfiles: addEmails,
        removeProfiles: removeEmails
    };
    return await request(`${constants_1.BASE_URL}/${constants_1.API_VERSION}/webhooks/twilio/audience/sync`, {
        method: 'post',
        json
    });
}
//# sourceMappingURL=functions.js.map