export const ROLE_PREFIX: Record = { TECHNICAL: "TCH", MANNING: "MAN", ACCOUNTS: "ACC", MANAGER: "MGR", SUPERUSER: "SUP", AUDITOR: "AUD", ADMIN: "ADM", }; /** Find max existing number for prefix and return prefix-(max+1), zero-padded to 3 digits */ export function nextId(prefix: string, existingIds: (string | null | undefined)[]): string { const re = new RegExp(`^${prefix}-(\\d+)$`, "i"); let max = 0; for (const id of existingIds) { if (!id) continue; const m = id.match(re); if (m) max = Math.max(max, parseInt(m[1], 10)); } return `${prefix}-${String(max + 1).padStart(3, "0")}`; }