/*
 * Copyright 2013-2021 consulo.io
 *
 * 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 consulo.externalService.impl.repository.history;

import consulo.externalService.impl.WebServiceApi;
import consulo.externalService.impl.WebServiceApiSender;
import consulo.logging.Logger;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Map;

/**
 * @author VISTALL
 * @since 20/11/2021
 */
public class PluginHistoryManager {
  private static final Logger LOG = Logger.getInstance(PluginHistoryManager.class);

  @Nonnull
  public static PluginHistoryEntry[] fetchHistory(@Nonnull String pluginId, @Nonnull String fromVersion, @Nonnull String toVersion) {
    Map<String, String> params;
    String baseUrl;
    if (fromVersion.equals(toVersion)) {
      baseUrl = "history/listByVersion";
      params = Map.of("id", pluginId, "version", fromVersion, "includeFromVersion", "false");
    }
    else {
      baseUrl = "history/listByVersionRange";
      params = Map.of("id", pluginId, "fromVersion", fromVersion, "toVersion", toVersion, "includeFromVersion", "false");
    }

    try {
      return WebServiceApiSender.doGet(WebServiceApi.REPOSITORY_API, baseUrl, params, PluginHistoryEntry[].class);
    }
    catch (IOException e) {
      LOG.warn(e);
      return new PluginHistoryEntry[0];
    }
  }
}

@@ -1374,24 +1374,26 @@
  fromVersion
+/*
 , %22includeFr
@@ -1403,32 +1403,34 @@
 ersion%22, %22false%22
+*/
 );%0A    %7D%0A    els
@@ -1567,16 +1567,18 @@
 oVersion
+/*
 , %22inclu
@@ -1600,16 +1600,18 @@
  %22false%22
+*/
 );%0A    %7D

include from