"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformAclPermissionToEntityPermissionPolicy = void 0;
const IEntityPermissionPolicy_1 = require("../../permissions/types/IEntityPermissionPolicy");
const ChannelBusinessRules_1 = require("./ChannelBusinessRules");
const role_1 = require("../../discussions/api/enums/role");
const aclCategory_1 = require("../../discussions/api/enums/aclCategory");
const aclSubCategory_1 = require("../../discussions/api/enums/aclSubCategory");
const ROLE_TO_PERMISSION_MAP = {
    [role_1.Role.READ]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelRead,
    [role_1.Role.WRITE]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelWrite,
    [role_1.Role.READWRITE]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelReadWrite,
    [role_1.Role.MODERATE]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelModerate,
    [role_1.Role.MANAGE]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelManage,
    [role_1.Role.OWNER]: ChannelBusinessRules_1.CHANNEL_PERMISSIONS.channelOwner,
};
/**
 * @private
 * Transforms an IChannelAclPermission-like object to an IEntityPermissionPolicy object
 * @param channelAclPermission An IChannelAclPermission-like object
 * @returns an IEntityPermissionPolicy object
 */
const transformAclPermissionToEntityPermissionPolicy = (channelAclPermission) => {
    const permission = ROLE_TO_PERMISSION_MAP[channelAclPermission.role];
    let collaborationType;
    if (channelAclPermission.category === aclCategory_1.AclCategory.ANONYMOUS_USER) {
        collaborationType = IEntityPermissionPolicy_1.COLLABORATION_TYPES.anonymous;
    }
    else if (channelAclPermission.category === aclCategory_1.AclCategory.AUTHENTICATED_USER) {
        collaborationType = IEntityPermissionPolicy_1.COLLABORATION_TYPES.authenticated;
    }
    else if (channelAclPermission.category === aclCategory_1.AclCategory.GROUP) {
        collaborationType =
            channelAclPermission.subCategory === aclSubCategory_1.AclSubCategory.ADMIN
                ? IEntityPermissionPolicy_1.COLLABORATION_TYPES.groupAdmin
                : IEntityPermissionPolicy_1.COLLABORATION_TYPES.group;
    }
    else if (channelAclPermission.category === aclCategory_1.AclCategory.ORG) {
        collaborationType =
            channelAclPermission.subCategory === aclSubCategory_1.AclSubCategory.ADMIN
                ? IEntityPermissionPolicy_1.COLLABORATION_TYPES.orgAdmin
                : IEntityPermissionPolicy_1.COLLABORATION_TYPES.org;
    }
    else {
        collaborationType = IEntityPermissionPolicy_1.COLLABORATION_TYPES.user;
    }
    return {
        permission,
        collaborationId: channelAclPermission.key || null,
        collaborationType,
        id: channelAclPermission.id || null,
    };
};
exports.transformAclPermissionToEntityPermissionPolicy = transformAclPermissionToEntityPermissionPolicy;
//# sourceMappingURL=transformAclPermissionToEntityPermissionPolicy.js.map