"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unshareEventWithGroups = unshareEventWithGroups;
const events_1 = require("../api/events");
/**
 * Unshares an event with one or more groups
 * @param groupIds An array of group IDs to unshare the group from
 * @param entity An IHubEvent object
 * @param context An IArcGISContext object
 * @returns An updated IHubEvent object
 */
async function unshareEventWithGroups(groupIds, entity, context) {
    if (groupIds.length) {
        try {
            const { readGroups: updatedReadGroupIds, editGroups: updatedEditGroupIds, } = await (0, events_1.updateEvent)(Object.assign({ eventId: entity.id, data: {
                    readGroups: entity.readGroupIds.filter((groupId) => !groupIds.includes(groupId)),
                    editGroups: entity.editGroupIds.filter((groupId) => !groupIds.includes(groupId)),
                } }, context.hubRequestOptions));
            return Object.assign(Object.assign({}, entity), { readGroupIds: updatedReadGroupIds, editGroupIds: updatedEditGroupIds });
        }
        catch (_e) {
            throw new Error(`Entity: ${entity.id} could not be unshared with groups: ${groupIds.join(", ")}`);
        }
    }
    else {
        return entity;
    }
}
//# sourceMappingURL=unshareEventWithGroups.js.map