export const AUTH = {
  VIEW_USER:      "VIEW_USER",
  MAINTAIN_USER:  "MAINTAIN_USER",
  VIEW_GROUP:     "VIEW_GROUP",
  MAINTAIN_GROUP: "MAINTAIN_GROUP",
  TESTING:        "TESTING",
  PROD:           "PROD",
  PACK:           "PACK",
  ADMIN:          "ADMIN",
  STOCK:          "STOCK",
  INVENTORY_ADJUST: "INVENTORY_ADJUST",
  ITEM_TRACING:   "ITEM_TRACING",
  PURCHASE:       "PURCHASE", 
  STOCK_TAKE:     "STOCK_TAKE", 
  STOCK_IN_BIND:  "STOCK_IN_BIND", 
  STOCK_FG:       "STOCK_FG", 
  FORECAST:       "FORECAST", 
  JOB_CREATE:     "JOB_CREATE", 
  JOB_PICK:       "JOB_PICK", 
  JOB_MAT:        "JOB_MAT", 
  JOB_PROD:       "JOB_PROD",
  /**
   * FP-MTMS Version Checklist | Functions Ref. No. 51 | v1.0.0 | 2026-08-05
   * 工單 生產流程 完成工單
   */
  PRODUCT_PROCESS: "PRODUCT_PROCESS",
  REPORT_MGMT:    "REPORT_MGMT",
} as const;

/**
 * FP-MTMS Version Checklist | Functions Ref. No. 51 | v1.0.0 | 2026-08-05
 * Match session ability codes (exact, trimmed).
 */
export function hasAbility(
  abilities: string[] | undefined | null,
  required: string,
): boolean {
  const code = required.trim();
  return (abilities ?? []).some((a) => String(a).trim() === code);
}