import { OrganizationMemberRole } from '../types/organizationMemberProfile';
import { ProjectMemberRole, ProjectRoleOrder, SpaceRoleOrder, } from '../types/projectMemberRole';
import { SpaceMemberRole } from '../types/space';
import assertUnreachable from './assertUnreachable';
export const convertOrganizationRoleToProjectRole = (organizationRole) => {
    switch (organizationRole) {
        case OrganizationMemberRole.VIEWER:
            return ProjectMemberRole.VIEWER;
        case OrganizationMemberRole.INTERACTIVE_VIEWER:
            return ProjectMemberRole.INTERACTIVE_VIEWER;
        case OrganizationMemberRole.EDITOR:
            return ProjectMemberRole.EDITOR;
        case OrganizationMemberRole.DEVELOPER:
            return ProjectMemberRole.DEVELOPER;
        case OrganizationMemberRole.ADMIN:
            return ProjectMemberRole.ADMIN;
        case OrganizationMemberRole.MEMBER:
            return undefined;
        default:
            return assertUnreachable(organizationRole, `Unknown role ${organizationRole}`);
    }
};
export const convertSpaceRoleToProjectRole = (spaceRole) => {
    switch (spaceRole) {
        case SpaceMemberRole.VIEWER:
            return ProjectMemberRole.VIEWER;
        case SpaceMemberRole.EDITOR:
            return ProjectMemberRole.EDITOR;
        case SpaceMemberRole.ADMIN:
            return ProjectMemberRole.ADMIN;
        default:
            return assertUnreachable(spaceRole, `Unknown space role ${spaceRole}`);
    }
};
export const getHighestProjectRole = (inheritedRoles) => inheritedRoles.reduce((highestRole, role) => {
    if (role.role === undefined) {
        return highestRole;
    }
    if (highestRole?.role === undefined ||
        ProjectRoleOrder[role.role] >=
            ProjectRoleOrder[highestRole.role]) {
        return {
            type: role.type,
            role: role.role,
        };
    }
    return highestRole;
}, undefined);
export const getHighestSpaceRole = (spaceRoles) => spaceRoles
    .filter((role) => role !== undefined)
    .sort((a, b) => SpaceRoleOrder[a] - SpaceRoleOrder[b])
    .reverse()[0];
export const convertProjectRoleToSpaceRole = (projectRole) => {
    switch (projectRole) {
        case ProjectMemberRole.VIEWER:
            return SpaceMemberRole.VIEWER;
        case ProjectMemberRole.INTERACTIVE_VIEWER:
            return SpaceMemberRole.VIEWER;
        case ProjectMemberRole.EDITOR:
            return SpaceMemberRole.EDITOR;
        case ProjectMemberRole.DEVELOPER:
            return SpaceMemberRole.EDITOR;
        case ProjectMemberRole.ADMIN:
            return SpaceMemberRole.ADMIN;
        default:
            return assertUnreachable(projectRole, `Project role ${projectRole} does not match Space roles`);
    }
};
export const convertProjectRoleToOrganizationRole = (projectRole) => {
    switch (projectRole) {
        case ProjectMemberRole.VIEWER:
            return OrganizationMemberRole.VIEWER;
        case ProjectMemberRole.INTERACTIVE_VIEWER:
            return OrganizationMemberRole.INTERACTIVE_VIEWER;
        case ProjectMemberRole.EDITOR:
            return OrganizationMemberRole.EDITOR;
        case ProjectMemberRole.DEVELOPER:
            return OrganizationMemberRole.DEVELOPER;
        case ProjectMemberRole.ADMIN:
            return OrganizationMemberRole.ADMIN;
        default:
            return assertUnreachable(projectRole, `Project role ${projectRole} does not match Organization roles`);
    }
};
//# sourceMappingURL=projectMemberRole.js.map