import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../tslib.es6-848120af.js';
import { batchSendWxRobotMarkdown } from '../wecom-robot/batch-send.mjs';
import { getWeatherRobotContent } from './weather.mjs';
import '../wecom-robot/base.mjs';
import '../wecom-robot/helper.mjs';
import 'axios';
import '../wecom-robot/send-img.mjs';
import '../node-img/img.mjs';
import '../nodejs/crypto.mjs';
import '../nodejs/fs.mjs';
import '../nodejs/request.mjs';
import '../nodejs/path.mjs';
import './api.mjs';
import './parse.mjs';
import '../fs/fs-util.mjs';
import '@babel/runtime/helpers/toConsumableArray';
import '../fs/fs.mjs';
import '../nodejs/os.mjs';
import '../time/time.mjs';

/**
 * 获取天气信息并发送
 * @param {object} options 配置
 * @param {string} options.webhookUrl 机器人hook地址
 * @param {string} [options.chatId] 会话Id
 * @param {string} [options.force] 是否在和之前获取数据相同时，也发送
 * @returns {Promise<Object>} 请求Promise
 * @example
 * ```ts
 * await sendWeatherRobotMsg({
 *   webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx',
 *   chatId: ['chat-id-1', 'chat-id-2'],
 *   force: false, // 默认 false：和上次数据一致时不发送
 * });
 * ```
 */
function sendWeatherRobotMsg(_ref) {
  var webhookUrl = _ref.webhookUrl,
    chatId = _ref.chatId,
    _ref$force = _ref.force,
    force = _ref$force === void 0 ? false : _ref$force;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var _yield$getWeatherRobo, content, isSame;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return getWeatherRobotContent();
        case 1:
          _yield$getWeatherRobo = _context.sent;
          content = _yield$getWeatherRobo.content;
          isSame = _yield$getWeatherRobo.isSame;
          console.log('[sendWeatherRobotMsg] 天气是否有变化: ', !isSame);
          if (!(!isSame || force)) {
            _context.next = 2;
            break;
          }
          return _context.abrupt("return", batchSendWxRobotMarkdown({
            webhookUrl: webhookUrl,
            chatId: chatId,
            content: content
          }));
        case 2:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { sendWeatherRobotMsg };
