class CameraUrlGenerator {

  @VisibleForTesting
  static String addHttpParams(String input, Map<String, String> commands) {
    if (commands.isEmpty()) {
      return input;
    }
    // Parse the URI
    URI uri;
    try {
      uri = new URI(input);
    } catch (URISyntaxException ex) {
      return input;
    }

    String query = uri.getQuery();

    if (query != null) {
      // Handle the NI special case
      String niName = commands.get("name");

      String[] existingCommands = query.split("&");
      for (String command : existingCommands) {
        String[] commandSplit = command.split("=");
        if (commandSplit.length != 2) {
          continue;
        }
        commands.put(URLDecoder.decode(commandSplit[0], StandardCharsets.UTF_8),
                     URLDecoder.decode(commandSplit[1], StandardCharsets.UTF_8));
      }
      if (niName != null) {
        commands.put("name", niName);
      }
    }

    var queryStr = commands.entrySet().stream()
        .map(CameraUrlGenerator::httpUrlEncode)
        .collect(Collectors.joining("&"));
    return encodeUri(uri, queryStr);

  }

  public  CameraUrlGenerator(CameraServerSource source);

}