import { getCoupledOrgRoleCodeForWorkspace, getCoupledWorkspaceForOrgRole, getOrgRoleByCode, getWorkspaceLabel, type StaffWorkspace, } from './staffRoleCatalog'; export type CoupledRemovalTarget = | { kind: 'role'; code: string } | { kind: 'workspace'; workspace: StaffWorkspace }; export interface CoupledRemovalDescription { removedLabel: string; partnerLabel: string; message: string; } const roleLabel = (code: string): string => getOrgRoleByCode(code)?.display ?? code; // Returns undefined when the target is not half of a coupled pair - callers use that to mean // "remove immediately, show no dialog". All pair knowledge comes from staffRoleCatalog. export const describeCoupledRemoval = ( target: CoupledRemovalTarget, ): CoupledRemovalDescription | undefined => { if (target.kind === 'role') { const workspace = getCoupledWorkspaceForOrgRole(target.code); if (!workspace) return undefined; const removedLabel = roleLabel(target.code); const partnerLabel = getWorkspaceLabel(workspace); return { removedLabel, partnerLabel, message: `Removing the ${removedLabel} role will also remove the ${partnerLabel} workspace.`, }; } const code = getCoupledOrgRoleCodeForWorkspace(target.workspace); if (!code) return undefined; const removedLabel = getWorkspaceLabel(target.workspace); const partnerLabel = roleLabel(code); return { removedLabel, partnerLabel, message: `Removing the ${removedLabel} workspace will also remove the ${partnerLabel} role.`, }; };