'use strict';

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

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../../tslib.es6-0d92ef81.js');
var canvas_multiImg = require('../../canvas/multi-img.js');
var wecomRobot_batchSend = require('../../wecom-robot/batch-send.js');
var tam_img_customEventImg = require('./custom-event-img.js');
var tam_img_summaryImg = require('./summary-img.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../nodejs/path.js');
require('../../third-party/image-size.js');
require('../../canvas/get-canvas.js');
require('../../third-party/canvas.js');
require('../../node-img/img.js');
require('../../nodejs/crypto.js');
require('../../nodejs/fs.js');
require('../../nodejs/request.js');
require('../../wecom-robot/base.js');
require('../../wecom-robot/helper.js');
require('axios');
require('../../wecom-robot/send-img.js');
require('../../canvas/table.js');
require('../../list/list.js');
require('../../time/time.js');
require('../api/custom-event.js');
require('../api/credential.js');
require('../parse/custom-event.js');
require('../../fs/fs-util.js');
require('../../fs/fs.js');
require('../../nodejs/os.js');
require('../../number/number.js');
require('../../list/parse-list.js');
require('../parse/header.js');
require('../../date/timeStamp.js');
require('../api/rum-score.js');
require('../../tencent-cloud/base/base.js');
require('../api/summary-score.js');
require('../parse/summary.js');

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

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

/**
 * 生成多个图片并发送机器人
 * @param {object} options 配置
 *
 * @example
 *
 * const requestMultiImgDate = Date.now() - 1 * 24 * 60 * 60 * 1000;
 *
 * const tamGroupIdList = [1, 2, 3];
 *
 * const summaryScoreTableHeaderMap = {
 *   ProjectName: {
 *     name: '项目名称',
 *     tableWidth: 95,
 *   },
 *   PagePv: {
 *     name: 'PV',
 *     tableWidth: 65,
 *   },
 * };
 *
 * const eventProjectMap = {
 *   62659: {
 *     name: 'aaaaa',
 *   },
 *   57706: {
 *     name: 'bbbbb',
 *     extraProjectId: 66379,
 *   },
 * };
 *
 * const eventMap = {
 *   WX_SUC: {
 *     // 总和
 *     type: 'SUMMARY',
 *     target: ['ENTER_GAME_WX_SUC', 'LAUNCH_GAME_SUC_WX'],
 *   },
 *   WX_FAIL: {
 *     // 总和
 *     type: 'SUMMARY',
 *     target: ['ENTER_GAME_WX_FAIL', 'LAUNCH_GAME_FAIL_WX'],
 *   },
 * };
 *
 * const eventTableHeaderMap = {
 *   ProjectName: {
 *     name: '项目名称',
 *     tableWidth: 95,
 *   },
 *   ALL_SUMMARY: {
 *     name: '拉起总数',
 *     tableWidth: 65,
 *   },
 * };
 *
 * await genMultiImgAndSendRobot({
 *   date: requestMultiImgDate,
 *   secretInfo: {
 *     getPwdCode,
 *     encrypt,
 *     apiKey: process.env.AEGIS_APP_KEY,
 *     loginName: 'lee',
 *   },
 *   webhookUrl: tamRobotWebhook,
 *   chatId: tamRobotChatId,
 *
 *   groupIdList: tamGroupIdList,
 *   eventProjectIdMap: eventProjectMap,
 *   tableHeaderMap: summaryScoreTableHeaderMap,
 *
 *   eventMap,
 *   eventTableHeaderMap,
 * });
 *
 *
 */
function genMultiImgAndSendRobot(_ref) {
  var date = _ref.date,
    groupIdList = _ref.groupIdList,
    secretInfo = _ref.secretInfo,
    _ref$extraDataMap = _ref.extraDataMap,
    extraDataMap = _ref$extraDataMap === void 0 ? {} : _ref$extraDataMap,
    _ref$ignoreProjectIdL = _ref.ignoreProjectIdList,
    ignoreProjectIdList = _ref$ignoreProjectIdL === void 0 ? [] : _ref$ignoreProjectIdL,
    _ref$tableHeaderMap = _ref.tableHeaderMap,
    tableHeaderMap = _ref$tableHeaderMap === void 0 ? {} : _ref$tableHeaderMap,
    webhookUrl = _ref.webhookUrl,
    chatId = _ref.chatId,
    _ref$env = _ref.env,
    env = _ref$env === void 0 ? 'production' : _ref$env,
    eventMap = _ref.eventMap,
    eventProjectIdMap = _ref.eventProjectIdMap,
    eventTableHeaderMap = _ref.eventTableHeaderMap;
  return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    var result, summaryScoreImg, data, launchGameImg, img;
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return tam_img_summaryImg.genSummaryData({
            date: date,
            groupIdList: groupIdList,
            secretInfo: secretInfo,
            extraDataMap: extraDataMap,
            ignoreProjectIdList: ignoreProjectIdList,
            tableHeaderMap: tableHeaderMap
          });
        case 1:
          result = _context.sent;
          if (result) {
            _context.next = 2;
            break;
          }
          return _context.abrupt("return");
        case 2:
          summaryScoreImg = result.img, data = result.data;
          _context.next = 3;
          return tam_img_customEventImg.genCustomEventImg({
            date: date,
            projectIdMap: eventProjectIdMap,
            env: env,
            secretInfo: secretInfo,
            eventMap: eventMap,
            tableHeaderMap: eventTableHeaderMap
          });
        case 3:
          launchGameImg = _context.sent;
          if (launchGameImg) {
            _context.next = 4;
            break;
          }
          return _context.abrupt("return");
        case 4:
          _context.next = 5;
          return canvas_multiImg.mergeMultiCanvasPic({
            imgs: [summaryScoreImg, launchGameImg]
          });
        case 5:
          img = _context.sent;
          if (!(!img || !chatId)) {
            _context.next = 6;
            break;
          }
          return _context.abrupt("return");
        case 6:
          _context.next = 7;
          return wecomRobot_batchSend.batchSendWxRobotBase64Img({
            img: img,
            webhookUrl: webhookUrl,
            chatId: chatId
          });
        case 7:
          return _context.abrupt("return", data);
        case 8:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

exports.genMultiImgAndSendRobot = genMultiImgAndSendRobot;
