type PermissionsMap = Record<string, Record<string, string>>;

/**
 * Collect scope keys from one or more module permission maps.
 * Each argument is a permissions object from definePermissions (e.g., userManagementPermissions).
 */
export function collectPermissionScopes(...permissionMaps: PermissionsMap[]): string[] {
  const scopes: string[] = [];

  for (const map of permissionMaps) {
    for (const [, commands] of Object.entries(map)) {
      const keys = Object.values(commands);
      if (keys.length === 0) continue;
      const scopeKey = keys[0].substring(0, keys[0].lastIndexOf(":"));
      scopes.push(scopeKey);
    }
  }

  return scopes.sort();
}
