"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dd_api_1 = __importDefault(require("../dd-api"));
class DDCampaignApi extends dd_api_1.default {
    constructor(settings, client) {
        super(settings, client);
    }
    async getCampaignsPaging(select = 1000, skip = 0) {
        return await this.get('/v2/campaigns', { select, skip });
    }
    async getCampaigns() {
        const choices = [];
        const select = 200;
        let skip = 0;
        let hasMoreData = true;
        while (hasMoreData) {
            const response = await this.getCampaignsPaging(select, skip);
            const content = JSON.parse(response.content);
            if (content.length === 0) {
                hasMoreData = false;
                break;
            }
            else {
                choices.push(...content.map((campaign) => ({
                    value: campaign.id.toString(),
                    label: campaign.name
                })));
                skip += select;
            }
        }
        return { choices: choices };
    }
    async sendCampaign(campaignId, contactId, sendDate, sendTimeOptimised) {
        const sendCampaignPayload = {
            campaignID: campaignId,
            contactIDs: [contactId],
            sendDate: sendDate
        };
        let endpoint = `/v2/campaigns/send`;
        if (sendTimeOptimised) {
            endpoint = `/v2/campaigns/send-time-optimised`;
            delete sendCampaignPayload.sendDate;
        }
        const response = await this.post(endpoint, sendCampaignPayload);
        return response;
    }
}
exports.default = DDCampaignApi;
//# sourceMappingURL=dd-campaign-api.js.map