import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../../tslib.es6-848120af.js';
import { mergeMultiCanvasPic } from '../../canvas/multi-img.mjs';
import { batchSendWxRobotBase64Img } from '../../wecom-robot/batch-send.mjs';
import { genCustomEventImg } from './custom-event-img.mjs';
import { genSummaryData } from './summary-img.mjs';
import '@babel/runtime/helpers/toConsumableArray';
import '../../node-img/img.mjs';
import '../../nodejs/crypto.mjs';
import '../../nodejs/fs.mjs';
import '../../nodejs/request.mjs';
import '../../nodejs/path.mjs';
import '../../third-party/image-size.mjs';
import '../../canvas/get-canvas.mjs';
import '../../third-party/canvas.mjs';
import '../../wecom-robot/base.mjs';
import '../../wecom-robot/helper.mjs';
import 'axios';
import '../../wecom-robot/send-img.mjs';
import '../../list/parse-list.mjs';
import '../../number/number.mjs';
import '../../canvas/table.mjs';
import '../../list/list.mjs';
import '../../time/time.mjs';
import '@babel/runtime/helpers/typeof';
import '../../date/timeStamp.mjs';
import '../api/custom-event.mjs';
import '../api/credential.mjs';
import '../parse/header.mjs';
import '../parse/custom-event.mjs';
import '../../fs/fs-util.mjs';
import '../../fs/fs.mjs';
import '../../nodejs/os.mjs';
import '../api/rum-score.mjs';
import '../../tencent-cloud/base/base.mjs';
import '../api/summary-score.mjs';
import '../parse/summary.mjs';

/**
 * 生成多个图片并发送机器人
 * @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 __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var result, summaryScoreImg, data, launchGameImg, img;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return 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 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 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 batchSendWxRobotBase64Img({
            img: img,
            webhookUrl: webhookUrl,
            chatId: chatId
          });
        case 7:
          return _context.abrupt("return", data);
        case 8:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { genMultiImgAndSendRobot };
