"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.reduceByGroupMembership = reduceByGroupMembership;
exports.isOrgAdmin = isOrgAdmin;
exports.isUserInOrg = isUserInOrg;
exports.isOrgAdminInOrg = isOrgAdminInOrg;
exports.userHasPrivilege = userHasPrivilege;
exports.userHasPrivileges = userHasPrivileges;
/**
 * Utility that returns reducer function that filters a user's groups
 * by membership type and produces an array of group id's
 *
 *
 * @export
 * @param {GroupMembership[]} membershipTypes
 * @return {*}  {((memo: string[], group: IGroup) => string[])}
 */
function reduceByGroupMembership(membershipTypes) {
    return function (memo, group) {
        if (membershipTypes.indexOf(group.userMembership.memberType) > -1) {
            memo.push(group.id);
        }
        return memo;
    };
}
/**
 * Utility that checks if a user is a portal org admin, or an org_admin by a platform role
 *
 * @export
 * @param {IUser} user
 * @return {*}  {boolean}
 */
// NOTE: this is not the same as @esri/arcgis-rest-portal isOrgAdmin,
// which first resolves `user` from `IUserRequestOptions` to make this determination
// https://github.com/Esri/arcgis-rest-js/blob/7ab072184f89dcb35367518101ee4abeb5a9d112/packages/arcgis-rest-portal/src/sharing/helpers.ts#L45
function isOrgAdmin(user) {
    return user.role === "org_admin";
}
function isUserInOrg(user = {}, orgId) {
    return user.orgId === orgId;
}
function isOrgAdminInOrg(user, orgId) {
    return isOrgAdmin(user) && isUserInOrg(user, orgId);
}
function userHasPrivilege(user = {}, privilege) {
    var _a;
    return !!((_a = user.privileges) === null || _a === void 0 ? void 0 : _a.includes(privilege));
}
function userHasPrivileges(user = {}, privileges) {
    return privileges.every((privilege) => userHasPrivilege(user, privilege));
}
//# sourceMappingURL=platform.js.map