"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAudienceByName = getAudienceByName;
exports.getAudienceByID = getAudienceByID;
exports.createAudience = createAudience;
const constants_1 = require("./constants");
async function getAudienceByName(request, settings, name) {
    const response = await request(`${constants_1.CONSTANTS.API_BASE_URL}${constants_1.CONSTANTS.API_CUSTOM_AUDIENCE_ENDPOINT}`, {
        method: 'GET',
        skipResponseCloning: true,
        headers: { 'Api-Key': settings.apiKey }
    });
    const json = (await response.data);
    const audience = json.lists.find((list) => list.name === name);
    return audience?.id.toString() ?? undefined;
}
async function getAudienceByID(request, settings, ID) {
    const response = await request(`${constants_1.CONSTANTS.API_BASE_URL}${constants_1.CONSTANTS.API_CUSTOM_AUDIENCE_ENDPOINT}`, {
        method: 'GET',
        skipResponseCloning: true,
        headers: { 'Api-Key': settings.apiKey }
    });
    const json = (await response.data);
    const audience = json.lists.find((list) => list.id.toString() === ID);
    return audience?.id.toString() ?? undefined;
}
async function createAudience(request, settings, name) {
    const response = await request(`${constants_1.CONSTANTS.API_BASE_URL}${constants_1.CONSTANTS.API_CUSTOM_AUDIENCE_ENDPOINT}`, {
        method: 'POST',
        headers: { 'Api-Key': settings.apiKey },
        json: {
            name
        }
    });
    const audience = await response.json();
    return audience.listId;
}
//# sourceMappingURL=functions.js.map