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

function getUpdateQQMpResultRows(_ref) {
  var result = _ref.result;
  var time = result.time,
    branch = result.branch,
    env = result.env,
    robot = result.robot,
    version = result.version,
    lastCommit = result.lastCommit,
    link = result.link;
  var rowValues = [time, branch, env, robot, version, lastCommit].map(function (item) {
    return {
      cellValue: {
        text: item
      }
    };
  });
  rowValues.push({
    cellValue: {
      link: {
        url: link,
        text: link
      }
    }
  });
  var rows = [{
    values: rowValues
  }];
  return rows;
}
function updateQQMpResultToSheet(_ref2) {
  var result = _ref2.result,
    accessToken = _ref2.accessToken,
    clientId = _ref2.clientId,
    openId = _ref2.openId,
    bookId = _ref2.bookId,
    sheetId = _ref2.sheetId,
    startRow = _ref2.startRow,
    _ref2$startColumn = _ref2.startColumn,
    startColumn = _ref2$startColumn === void 0 ? 1 : _ref2$startColumn;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var rows;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          rows = getUpdateQQMpResultRows({
            result: result
          });
          if (startRow) {
            _context.next = 1;
            break;
          }
          console.log('[updateQQMpResultToSheet.error] startRow 不可为空，且必须大于等于1');
          return _context.abrupt("return");
        case 1:
          _context.next = 2;
          return batchUpdateTencentSheetV3({
            accessToken: accessToken,
            clientId: clientId,
            openId: openId,
            bookId: bookId,
            requests: [{
              updateRangeRequest: {
                sheetId: sheetId,
                gridData: {
                  startRow: startRow - 1,
                  startColumn: startColumn,
                  rows: rows
                }
              }
            }]
          });
        case 2:
          return _context.abrupt("return", _context.sent);
        case 3:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { updateQQMpResultToSheet };
