"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dynamicFields = void 0;
exports.dynamicFields = {
    campaign_id: async (request, { settings }) => {
        try {
            const allCampaigns = [];
            let page = 0;
            while (true) {
                const response = await request(`${settings.endpoint}/campaigns/list`, {
                    method: 'GET',
                    skipResponseCloning: true,
                    searchParams: {
                        page: page.toString()
                    }
                });
                const data = response.data;
                if (!data.campaigns || !Array.isArray(data.campaigns) || data.campaigns.length === 0) {
                    break;
                }
                if (data.campaigns) {
                    allCampaigns.push(...data.campaigns);
                }
                page++;
            }
            if (allCampaigns.length === 0) {
                return {
                    choices: [],
                    error: {
                        message: 'No campaigns found in your Braze account',
                        code: '404'
                    }
                };
            }
            const campaigns = allCampaigns.map((campaign) => ({
                label: campaign.name,
                value: campaign.id
            }));
            return {
                choices: campaigns
            };
        }
        catch (error) {
            return {
                choices: [],
                error: {
                    message: error.message || 'Failed to fetch campaigns from Braze API',
                    code: error.status || '500'
                }
            };
        }
    }
};
//# sourceMappingURL=dynamic-field-functions.js.map