import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../../tslib.es6-848120af.js';
import { fetchCloudData } from '../base/base.mjs';
import 'axios';
import '../../nodejs/crypto.mjs';

/**
 * 获取腾讯云 RUM（Real User Monitoring）性能数据
 * 用于查询前端性能监控数据，支持按时间范围和类型筛选
 * @param secretId - 腾讯云 SecretId
 * @param secretKey - 腾讯云 SecretKey
 * @param id - RUM 项目 ID
 * @param startTime - 开始时间（时间戳或字符串）
 * @param endTime - 结束时间（时间戳或字符串）
 * @param type - 性能数据类型
 * @returns {Promise<{data: Array<unknown>}>} - 返回性能数据数组
 * @example
 * ```ts
 * getRUMPerformance({
 *   secretId: 'your-secret-id',
 *   secretKey: 'your-secret-key',
 *   id: '123456',
 *   startTime: 1640000000,
 *   endTime: 1640086400,
 *   type: 'page'
 * }).then(result => {
 *   console.log('性能数据:', result.data);
 * });
 * ```
 */
function getRUMPerformance(_ref) {
  var secretId = _ref.secretId,
    secretKey = _ref.secretKey,
    id = _ref.id,
    startTime = _ref.startTime,
    endTime = _ref.endTime,
    type = _ref.type;
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          return _context.abrupt("return", fetchCloudData({
            secretId: secretId,
            secretKey: secretKey,
            action: 'DescribeDataPerformancePage',
            payload: JSON.stringify({
              ID: id,
              StartTime: startTime,
              EndTime: endTime,
              Type: type
            })
          }).then(function (res) {
            var resp = res.data.Response || {};
            var _resp$Result = resp.Result,
              result = _resp$Result === void 0 ? '' : _resp$Result;
            var data = {
              results: []
            };
            try {
              data = JSON.parse(result);
            } catch (err) {}
            return {
              data: data.results || []
            };
          })["catch"](function (err) {
            console.log('[getRUMPerformance] err: ', err);
          }));
        case 1:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

export { getRUMPerformance };
