"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOrganizationRoleForSpaceAccess = exports.getProjectRoleForSpaceAccess = void 0;
const organizationMemberProfile_1 = require("../../types/organizationMemberProfile");
const projectMemberRole_1 = require("../../types/projectMemberRole");
/**
 * Project-role equivalent of a custom role for space-access resolution.
 *
 * Custom-role assignments persist a placeholder `viewer` in the legacy `role`
 * column of `project_memberships` / `project_group_access`, so the role that
 * flows into inherited spaces must be derived from the custom role's scopes.
 * The marker scopes mirror the system-role tiers: `manage:Space` is first
 * granted at admin and `manage:Space@public` at editor, so the derived role
 * converts to the same space role as the system role the scopes came from.
 */
const getProjectRoleForSpaceAccess = (scopes) => {
    if (scopes.includes('manage:Space')) {
        return projectMemberRole_1.ProjectMemberRole.ADMIN;
    }
    if (scopes.includes('manage:Space@public')) {
        return projectMemberRole_1.ProjectMemberRole.EDITOR;
    }
    return projectMemberRole_1.ProjectMemberRole.VIEWER;
};
exports.getProjectRoleForSpaceAccess = getProjectRoleForSpaceAccess;
/**
 * Organization-role equivalent of a custom role for space-access resolution.
 * Same derivation as `getProjectRoleForSpaceAccess` — org-level custom-role
 * assignments persist a placeholder `member` in `organization_memberships`,
 * which would otherwise grant no inherited space access at all.
 */
const getOrganizationRoleForSpaceAccess = (scopes) => {
    switch ((0, exports.getProjectRoleForSpaceAccess)(scopes)) {
        case projectMemberRole_1.ProjectMemberRole.ADMIN:
            return organizationMemberProfile_1.OrganizationMemberRole.ADMIN;
        case projectMemberRole_1.ProjectMemberRole.EDITOR:
            return organizationMemberProfile_1.OrganizationMemberRole.EDITOR;
        default:
            return organizationMemberProfile_1.OrganizationMemberRole.VIEWER;
    }
};
exports.getOrganizationRoleForSpaceAccess = getOrganizationRoleForSpaceAccess;
//# sourceMappingURL=customRoleProjectRole.js.map