import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../tslib.es6-848120af.js';
import axios from 'axios';

function reviewPipeline(_ref) {
  var host = _ref.host,
    projectId = _ref.projectId,
    buildId = _ref.buildId,
    pipelineId = _ref.pipelineId,
    stepId = _ref.stepId,
    elementId = _ref.elementId,
    _ref$reviewUsers = _ref.reviewUsers,
    reviewUsers = _ref$reviewUsers === void 0 ? ['novlan1'] : _ref$reviewUsers,
    status = _ref.status,
    suggest = _ref.suggest,
    params = _ref.params,
    _ref$accessToken = _ref.accessToken,
    accessToken = _ref$accessToken === void 0 ? '' : _ref$accessToken;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var url;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          if (host) {
            _context.next = 1;
            break;
          }
          return _context.abrupt("return", Promise.reject('host is empty'));
        case 1:
          if (projectId) {
            _context.next = 2;
            break;
          }
          return _context.abrupt("return", Promise.reject('projectId is empty'));
        case 2:
          if (buildId) {
            _context.next = 3;
            break;
          }
          return _context.abrupt("return", Promise.reject('buildId is empty'));
        case 3:
          if (pipelineId) {
            _context.next = 4;
            break;
          }
          return _context.abrupt("return", Promise.reject('pipelineId is empty'));
        case 4:
          if (elementId) {
            _context.next = 5;
            break;
          }
          return _context.abrupt("return", Promise.reject('elementId is empty'));
        case 5:
          url = "".concat(host, "/projects/").concat(projectId, "/manual_review?buildId=").concat(buildId, "&pipelineId=").concat(pipelineId, "&elementId=").concat(elementId, "&stepId=").concat(stepId);
          if (accessToken) {
            url += "&access_token=".concat(accessToken);
          }
          return _context.abrupt("return", new Promise(function (resolve) {
            axios({
              url: url,
              method: 'POST',
              headers: {
                'Content-Type': 'application/json'
              },
              data: {
                buildId: buildId,
                pipelineId: pipelineId,
                projectId: projectId,
                elementId: elementId,
                params: params,
                reviewUsers: reviewUsers,
                status: status,
                suggest: suggest
              }
            }).then(function (response) {
              resolve(response.data);
            })["catch"](function (error) {
              resolve(error.response.data);
            });
          }));
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { reviewPipeline };
