import { OrgRole } from '@prisma/client';

export interface UserPrincipal {
  type: 'user';
  userId: string;
  email: string;
}

export interface ApiKeyPrincipal {
  type: 'apiKey';
  apiKeyId: string;
  orgId: string;
  scopes: string[];
}

export type Principal = UserPrincipal | ApiKeyPrincipal;

// Rank order used by OrgRolesGuard: a required role means "at least this role".
export const ROLE_RANK: Record<OrgRole, number> = {
  VIEWER: 0,
  MEMBER: 1,
  ORG_ADMIN: 2,
};

export const API_KEY_SCOPES = [
  'jobs:read',
  'jobs:write',
  'points:read',
  'points:write',
  'devices:read',
] as const;
export type ApiKeyScope = (typeof API_KEY_SCOPES)[number];
