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

function createMRNote(_ref) {
  var privateToken = _ref.privateToken,
    _ref$gitApiPrefix = _ref.gitApiPrefix,
    gitApiPrefix = _ref$gitApiPrefix === void 0 ? T_GIT_BASE_URL : _ref$gitApiPrefix,
    projectName = _ref.projectName,
    mrId = _ref.mrId,
    body = _ref.body,
    path = _ref.path,
    line = _ref.line,
    _ref$lineType = _ref.lineType,
    lineType = _ref$lineType === void 0 ? 'new' : _ref$lineType,
    _ref$risk = _ref.risk,
    risk = _ref$risk === void 0 ? 3 : _ref$risk,
    _ref$resolveState = _ref.resolveState,
    resolveState = _ref$resolveState === void 0 ? 1 : _ref$resolveState,
    _ref$notifyEnabled = _ref.notifyEnabled,
    notifyEnabled = _ref$notifyEnabled === void 0 ? true : _ref$notifyEnabled;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          if (!(!mrId || !projectName || !privateToken)) {
            _context.next = 1;
            break;
          }
          return _context.abrupt("return", Promise.reject('参数不全'));
        case 1:
          return _context.abrupt("return", new Promise(function (resolve, reject) {
            axios({
              url: "".concat(gitApiPrefix, "/projects/").concat(encodeURIComponent(projectName), "/merge_requests/").concat(mrId, "/notes?private_token=").concat(privateToken),
              method: 'POST',
              data: {
                body: body,
                path: path,
                line: line,
                line_type: lineType,
                risk: risk,
                resolve_state: resolveState,
                notify_enabled: notifyEnabled
              }
            }).then(function (res) {
              resolve(res.data);
            })["catch"](function (err) {
              console.log('err', err);
              reject(err);
            });
          }));
        case 2:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}
function createMRComment(_ref2) {
  var projectName = _ref2.projectName,
    mrId = _ref2.mrId,
    data = _ref2.data,
    privateToken = _ref2.privateToken,
    _ref2$gitApiPrefix = _ref2.gitApiPrefix,
    gitApiPrefix = _ref2$gitApiPrefix === void 0 ? T_GIT_BASE_URL : _ref2$gitApiPrefix;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    return _regeneratorRuntime.wrap(function (_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          return _context2.abrupt("return", new Promise(function (resolve, reject) {
            axios({
              url: "".concat(gitApiPrefix, "/projects/").concat(encodeURIComponent(projectName), "/merge_request/").concat(mrId, "/comments?private_token=").concat(privateToken),
              method: 'POST',
              data: {
                note: data
              }
            }).then(function (res) {
              resolve(res.data);
            })["catch"](function (err) {
              console.log('err', err);
              reject(err);
            });
          }));
        case 1:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  }));
}

export { createMRComment, createMRNote };
