"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDirectoryIds = getDirectoryIds;
const qualtricsApiClient_1 = __importDefault(require("./qualtricsApiClient"));
async function getDirectoryIds(request, data) {
    const choices = [];
    const apiClient = new qualtricsApiClient_1.default(data.settings.datacenter, data.settings.apiToken, request);
    try {
        const response = await apiClient.listDirectories();
        for (const directory of response.elements) {
            choices.push({
                label: `${directory.name}`,
                value: directory.directoryId
            });
        }
    }
    catch (err) {
        return getError(err);
    }
    return {
        choices
    };
}
async function getError(err) {
    const errResponse = err?.response;
    const errorBody = (await errResponse.json());
    return {
        choices: [],
        error: {
            message: errorBody?.meta?.error?.errorMessage ?? 'Unknown Error',
            code: errResponse?.status.toString() ?? '500'
        }
    };
}
//# sourceMappingURL=dynamicFields.js.map