'use strict';

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

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../../tslib.es6-0d92ef81.js');
var tencentCloud_base_base = require('../base/base.js');
require('axios');
require('../../nodejs/crypto.js');

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

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

/**
 * 获取腾讯云 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 tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          return _context.abrupt("return", tencentCloud_base_base.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);
  }));
}

exports.getRUMPerformance = getRUMPerformance;
