import type { Role } from '@/lib/permissions';

/** Highest privilege wins for shell session (admin > editor > viewer). */
const ROLE_PRIORITY: Record<Role, number> = { admin: 3, editor: 2, viewer: 1 };

export function getPrimaryRole(roles: Role[]): Role {
  const list = roles?.length ? roles : (['viewer'] as Role[]);
  return list.reduce(
    (best, r) => (ROLE_PRIORITY[r] > ROLE_PRIORITY[best] ? r : best),
    list[0],
  );
}
