'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');
var tencentDoc_sheet = require('../tencent-doc/sheet.js');
var tencentDoc_tencentDoc = require('../tencent-doc/tencent-doc.js');
require('axios');
require('../nodejs/fs.js');
require('../third-party/form-data.js');
require('../third-party/qs.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);

function updateQQMpResultToSheetV0(_ref) {
  var accessToken = _ref.accessToken,
    clientId = _ref.clientId,
    openId = _ref.openId,
    bookId = _ref.bookId,
    sheetId = _ref.sheetId,
    startRow = _ref.startRow,
    qqMpQRCodePath = _ref.qqMpQRCodePath,
    result = _ref.result;
  return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    var uploadImageResult, updateImageResult, time, branch, env, robot, version, lastCommit, link, updateTextResult;
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return tencentDoc_tencentDoc.uploadTencentDocImage({
            accessToken: accessToken,
            clientId: clientId,
            openId: openId,
            image: qqMpQRCodePath
          });
        case 1:
          uploadImageResult = _context.sent;
          console.log('[CI] upload image result: ', uploadImageResult);
          if (!((uploadImageResult === null || uploadImageResult === void 0 ? void 0 : uploadImageResult.ret) != 0)) {
            _context.next = 2;
            break;
          }
          return _context.abrupt("return", uploadImageResult);
        case 2:
          _context.next = 3;
          return tencentDoc_sheet.updateTencentSheetImage({
            accessToken: accessToken,
            clientId: clientId,
            openId: openId,
            bookId: bookId,
            insertImages: {
              sheetID: sheetId,
              images: [{
                type: 1,
                imageID: uploadImageResult.data.imageID,
                width: 100,
                height: 100,
                row: startRow,
                col: 1,
                offsetX: null,
                offsetY: null,
                clip_info: null
              }]
            }
          });
        case 3:
          updateImageResult = _context.sent;
          console.log('[CI] update sheet image result: ', updateImageResult);
          if (!((updateImageResult === null || updateImageResult === void 0 ? void 0 : updateImageResult.ret) != 0)) {
            _context.next = 4;
            break;
          }
          return _context.abrupt("return", updateImageResult);
        case 4:
          time = result.time, branch = result.branch, env = result.env, robot = result.robot, version = result.version, lastCommit = result.lastCommit, link = result.link;
          _context.next = 5;
          return tencentDoc_sheet.updateTencentSheet({
            accessToken: accessToken,
            clientId: clientId,
            openId: openId,
            bookId: bookId,
            range: "".concat(sheetId, "!B").concat(startRow, ":H").concat(startRow),
            values: [[time, branch, env, robot, version, lastCommit, link]]
          });
        case 5:
          updateTextResult = _context.sent;
          console.log('[CI] update sheet text result: ', updateTextResult);
          return _context.abrupt("return", updateTextResult);
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

exports.updateQQMpResultToSheetV0 = updateQQMpResultToSheetV0;
