"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEventGroups = getEventGroups;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const events_1 = require("./api/events");
/**
 * Fetches the groups an event is shared with
 * @param eventId The ID of the event to fetch the groups for
 * @param context An IArcGISContext object
 * @returns
 */
async function getEventGroups(eventId, context) {
    const { editGroups: editGroupIds, readGroups: readGroupIds } = await (0, events_1.getEvent)(Object.assign({ eventId }, context.hubRequestOptions));
    const search = (ids) => ids.length
        ? (0, arcgis_rest_portal_1.searchGroups)(Object.assign({ q: `id:(${ids.join(" OR ")})`, num: ids.length }, context.requestOptions))
        : Promise.resolve({ results: [] });
    const [{ results: readGroups }, { results: editGroups }] = await Promise.all([readGroupIds, editGroupIds].map(search));
    return [...readGroups, ...editGroups];
}
//# sourceMappingURL=getEventGroups.js.map