"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setEntityAccess = setEntityAccess;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const getTypeFromEntity_1 = require("./getTypeFromEntity");
const events_1 = require("../events/api/events");
/**
 * Sets an entity's access to the given access
 * @param entity A HubEntity object
 * @param access The access to set the entity to
 * @param context An IArcGISContext object
 * @returns a promise
 */
async function setEntityAccess(entity, access, context) {
    const type = (0, getTypeFromEntity_1.getTypeFromEntity)(entity);
    switch (type) {
        case "event":
            await (0, events_1.updateEvent)(Object.assign({ eventId: entity.id, data: {
                    access: access.toUpperCase(),
                } }, context.hubRequestOptions));
            break;
        case "group":
            await (0, arcgis_rest_portal_1.updateGroup)({
                group: {
                    id: entity.id,
                    access,
                },
                authentication: context.session,
            });
            break;
        default:
            await (0, arcgis_rest_portal_1.setItemAccess)({
                id: entity.id,
                access,
                owner: entity.owner,
                authentication: context.session,
            });
            break;
    }
}
//# sourceMappingURL=setEntityAccess.js.map