"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createClient = createClient;

function _builderUtilRuntime() {
  const data = require("builder-util-runtime");

  _builderUtilRuntime = function () {
    return data;
  };

  return data;
}

function _BintrayProvider() {
  const data = require("./BintrayProvider");

  _BintrayProvider = function () {
    return data;
  };

  return data;
}

function _GenericProvider() {
  const data = require("./GenericProvider");

  _GenericProvider = function () {
    return data;
  };

  return data;
}

function _GitHubProvider() {
  const data = require("./GitHubProvider");

  _GitHubProvider = function () {
    return data;
  };

  return data;
}

function _PrivateGitHubProvider() {
  const data = require("./PrivateGitHubProvider");

  _PrivateGitHubProvider = function () {
    return data;
  };

  return data;
}

function createClient(data, updater) {
  // noinspection SuspiciousTypeOfGuard
  if (typeof data === "string") {
    throw (0, _builderUtilRuntime().newError)("Please pass PublishConfiguration object", "ERR_UPDATER_INVALID_PROVIDER_CONFIGURATION");
  }

  const httpExecutor = updater.httpExecutor;
  const provider = data.provider;

  switch (provider) {
    case "github":
      const githubOptions = data;
      const token = (githubOptions.private ? process.env.GH_TOKEN || process.env.GITHUB_TOKEN : null) || githubOptions.token;

      if (token == null) {
        return new (_GitHubProvider().GitHubProvider)(githubOptions, updater, httpExecutor);
      } else {
        return new (_PrivateGitHubProvider().PrivateGitHubProvider)(githubOptions, token, httpExecutor);
      }

    case "s3":
    case "spaces":
      return new (_GenericProvider().GenericProvider)({
        provider: "generic",
        url: (0, _builderUtilRuntime().getS3LikeProviderBaseUrl)(data),
        channel: data.channel || null
      }, updater, provider === "spaces"
      /* https://github.com/minio/minio/issues/5285#issuecomment-350428955 */
      );

    case "generic":
      const options = data;
      return new (_GenericProvider().GenericProvider)(options, updater, options.useMultipleRangeRequest !== false && !options.url.includes("s3.amazonaws.com"));

    case "bintray":
      return new (_BintrayProvider().BintrayProvider)(data, httpExecutor);

    default:
      throw (0, _builderUtilRuntime().newError)(`Unsupported provider: ${provider}`, "ERR_UPDATER_UNSUPPORTED_PROVIDER");
  }
} 
//# sourceMappingURL=providerFactory.js.map