"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPermissionPolicy = addPermissionPolicy;
exports.removePermissionPolicy = removePermissionPolicy;
const util_1 = require("../util");
/**
 * Add a policy to an array of entity policies
 * Returns a new array
 * @param permissions
 * @param policy
 * @returns
 */
function addPermissionPolicy(permissions = [], policy) {
    const clone = removePermissionPolicy(permissions, policy.permission, policy.collaborationId);
    clone.push(policy);
    return clone;
}
/**
 * Remove a policy from an array of entity policies
 * Returns a new array
 * @param permissions
 * @param permission
 * @param id
 * @returns
 */
function removePermissionPolicy(permissions = [], permission, id) {
    const clone = (0, util_1.cloneObject)(permissions);
    return clone.filter((p) => p.permission !== permission || p.collaborationId !== id);
}
//# sourceMappingURL=utils.js.map