// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.googlesource.gerrit.plugins.importer;

import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.List;

public class ChangeQuery extends RemoteQuery {

  private final String QUERY_PREFIX = "?q=";
  private final String DETAIL_SUFFIX =
      "&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS&o=MESSAGES"
      + "&o=CURRENT_REVISION&o=ALL_REVISIONS";

  ChangeQuery(String url, String user, String pass) {
    super(url, user, pass);
  }

  public List<ChangeInfo> query(String projectName) throws IOException {
    String endPoint =
        "/changes/" + QUERY_PREFIX + "project:" + projectName + DETAIL_SUFFIX;
    RestResponse r = getRestSession().get(endPoint);
    List<ChangeInfo> result =
        newGson().fromJson(r.getReader(),
            new TypeToken<List<ChangeInfo>>() {}.getType());
    return result;
  }
}

@@ -653,16 +653,78 @@
 orter;%0A%0A
+import com.google.gerrit.extensions.client.ListChangesOption;%0A
 import c
@@ -837,24 +837,50 @@
 OException;%0A
+import java.util.EnumSet;%0A
 import java.
@@ -943,198 +943,8 @@
  %7B%0A%0A
-  private final String QUERY_PREFIX = %22?q=%22;%0A  private final String DETAIL_SUFFIX =%0A      %22&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS&o=MESSAGES%22%0A      + %22&o=CURRENT_REVISION&o=ALL_REVISIONS%22;%0A%0A
   Ch
@@ -1143,28 +1143,11 @@
 ges/
-%22 + QUERY_PREFIX + %22
+?q=
 proj
@@ -1171,22 +1171,345 @@
 me +
- DETAIL_SUFFIX
+%0A        %22&O=%22 + Integer.toHexString(ListChangesOption.toBits(%0A            EnumSet.of(%0A                ListChangesOption.DETAILED_LABELS,%0A                ListChangesOption.DETAILED_ACCOUNTS,%0A                ListChangesOption.MESSAGES,%0A                ListChangesOption.CURRENT_REVISION,%0A                ListChangesOption.ALL_REVISIONS)))
 ;%0A  

Use ListChangesOption enum to set options on change query