function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

import { axios } from '@choerodon/boot';

function getPrefix(type) {
  return type === 'deploy' ? 'devops' : 'test';
}

var HostConfigApi = /*#__PURE__*/function () {
  function HostConfigApi() {
    _classCallCheck(this, HostConfigApi);
  }

  _createClass(HostConfigApi, null, [{
    key: "checkName",
    value: function checkName(projectId, name, type) {
      return axios.get("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/check/name_unique?name=").concat(name));
    }
  }, {
    key: "createHost",
    value: function createHost(projectId, type) {
      return "/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts");
    }
  }, {
    key: "editHost",
    value: function editHost(projectId, hostId, type) {
      return "/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/").concat(hostId);
    }
  }, {
    key: "testConnection",
    value: function testConnection(projectId, data, type) {
      return axios.post("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/connection_test"), JSON.stringify(data));
    }
  }, {
    key: "checkSshPort",
    value: function checkSshPort(projectId, ip, port, type) {
      return axios.get("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/check/ssh_unique?ip=").concat(ip, "&ssh_port=").concat(port));
    }
  }, {
    key: "checkJmeterPort",
    value: function checkJmeterPort(projectId, ip, port) {
      return axios.get("/test/v1/projects/".concat(projectId, "/hosts/check/jmeter_unique?ip=").concat(ip, "&jmeter_port=").concat(port));
    }
  }, {
    key: "getHostDetail",
    value: function getHostDetail(projectId, hostId, type) {
      return "/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/").concat(hostId);
    }
  }, {
    key: "getLoadHostsDetailsUrl",
    value: function getLoadHostsDetailsUrl(projectId, type) {
      return "/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/page_by_options?with_updater_info=true");
    }
  }, {
    key: "getDeleteHostUrl",
    value: function getDeleteHostUrl(projectId, hostId, type) {
      return axios["delete"]("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/").concat(hostId));
    }
  }, {
    key: "batchCorrect",
    value: function batchCorrect(projectId, data, type) {
      return axios.post("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/batch_correct"), JSON.stringify(data));
    } // 检查主机是否能被删除

  }, {
    key: "checkHostDeletable",
    value: function checkHostDeletable(projectId, hostId, type) {
      return axios.get("/".concat(getPrefix(type), "/v1/projects/").concat(projectId, "/hosts/check/delete?host_id=").concat(hostId));
    }
  }]);

  return HostConfigApi;
}();

export { HostConfigApi as default };