'use strict';

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

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');
var time_time = require('../time/time.js');
var wecomRobot_batchSend = require('../wecom-robot/batch-send.js');
var openSourceReport_api = require('./api.js');
var openSourceReport_parse = require('./parse.js');
require('../wecom-robot/base.js');
require('../wecom-robot/helper.js');
require('axios');
require('../wecom-robot/send-img.js');
require('../nodejs/path.js');
require('../node-img/img.js');
require('../nodejs/crypto.js');
require('../nodejs/fs.js');
require('../nodejs/request.js');
require('@babel/runtime/helpers/toConsumableArray');

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

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

var MAX_SHOW_LINK_NAME = 12;
/**
 * 请求开源治理数据并发送
 * @param options 配置信息
 * @example
 * ```ts
 * await sendOpenSourceReport({
 *   date: '2024-01-01',
 *   chatId: 'xxx',
 *   webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx',
 *   requestInfo: { ... },
 *   searchInfo: { ... },
 *   maxShowLinkNum: 12,
 *   whiteList: ['some-repo'],
 *   filterOrgPath: 'group/sub-group',
 * });
 * ```
 */
function sendOpenSourceReport(_ref) {
  var date = _ref.date,
    chatId = _ref.chatId,
    webhookUrl = _ref.webhookUrl,
    requestInfo = _ref.requestInfo,
    searchInfo = _ref.searchInfo,
    _ref$maxShowLinkNum = _ref.maxShowLinkNum,
    maxShowLinkNum = _ref$maxShowLinkNum === void 0 ? MAX_SHOW_LINK_NAME : _ref$maxShowLinkNum,
    _ref$whiteList = _ref.whiteList,
    whiteList = _ref$whiteList === void 0 ? [] : _ref$whiteList,
    _ref$filterOrgPath = _ref.filterOrgPath,
    filterOrgPath = _ref$filterOrgPath === void 0 ? '' : _ref$filterOrgPath;
  return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    var time, formattedDate, reportArr, chatContent, _t;
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          time = time_time.timeStampFormat(new Date(date).getTime(), 'yyyyMMdd');
          formattedDate = time_time.timeStampFormat(new Date(date).getTime(), 'yyyy-MM-dd');
          _context.next = 1;
          return openSourceReport_api.getOpenSourceReport(Object.assign({
            time: time
          }, requestInfo || {}));
        case 1:
          reportArr = _context.sent;
          chatContent = openSourceReport_parse.parseOpenSourceReport({
            reportArr: reportArr,
            date: time,
            formattedDate: formattedDate,
            requestInfo: requestInfo,
            searchInfo: searchInfo,
            maxShowLinkNum: maxShowLinkNum,
            whiteList: whiteList,
            filterOrgPath: filterOrgPath
          });
          if (chatContent) {
            _context.next = 2;
            break;
          }
          return _context.abrupt("return");
        case 2:
          _context.prev = 2;
          _context.next = 3;
          return wecomRobot_batchSend.batchSendWxRobotMarkdown({
            chatId: chatId,
            content: chatContent,
            webhookUrl: webhookUrl
          });
        case 3:
          _context.next = 5;
          break;
        case 4:
          _context.prev = 4;
          _t = _context["catch"](2);
          console.log('[sendOpenSourceReport] err', _t);
        case 5:
        case "end":
          return _context.stop();
      }
    }, _callee, null, [[2, 4]]);
  }));
}

exports.sendOpenSourceReport = sendOpenSourceReport;
