/**
 * @file atAllowRights.ts - Permissions definitions used by the Process Director system and associated types.
 * The {@link AtAllowRights} object acts as a const enum, and {@link AtAllowRightsLabels} provides a reverse lookup from numeric value back to the human-readable permission name.
 */

/**
 * Const object mapping permission names to their numeric identifiers as defined in the Process Director system.
 *
 * Grouped logically:
 * - 0       : System-level
 * - 1--7    : Folder-field and legacy permissions
 * - 10--13  : Document template permissions
 * - 20--22  : Queue and button permissions
 * - 30--38  : Process-level permissions (work items, documents, tracking, notes)
 * - 251--255: Administrative / application-wide roles
 */
export const AtAllowRights = {
  TheSystem: 0,
  ViewFolderField: 1,
  EditFolderField: 2,
  ViewFieldOrButton: 3,
  ListWorkitems: 4,
  ForwardWorkitems: 5,
  ProcessUseTemplate: 10,
  ViewDocField: 11,
  EditDocField: 12,
  ChangeDocumentTemplate: 13,
  UseQueue: 20,
  ViewButton: 21,
  ClickButton: 22,
  UseProcess: 30,
  CreateWorkitem: 31,
  AttachDocument: 32,
  DeleteDocument: 33,
  EditDocument: 34,
  DownloadDocument: 35,
  ViewTracking: 36,
  AddNote: 37,
  CloneWorkitems: 38,
  AdminaProcess: 251,
  Designer: 252,
  iAdmin: 253,
  RapidWorkPlace: 254,
  AllApplications: 255,
  LegacyPermissions: 7,
} as const;

/** Union type of all numeric permission values defined in {@link AtAllowRights} */
export type AtAllowRight = (typeof AtAllowRights)[keyof typeof AtAllowRights];

/**
 * Reverse lookup map that resolves a numeric {@link AtAllowRight} value back to its corresponding permission name string.
 */
export const AtAllowRightsLabels = Object.fromEntries(
  Object.entries(AtAllowRights).map(([key, value]) => [value, key])
) as Record<AtAllowRight, keyof typeof AtAllowRights>;
