'use strict';

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

var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');

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

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function parseOptions(options) {
  var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'msg';
  var innerOptions = {};
  if (typeof options === 'string') {
    innerOptions = _defineProperty__default["default"]({}, key, options);
  } else if (_typeof__default["default"](options) === 'object') {
    innerOptions = options;
  }
  innerOptions = Object.keys(innerOptions).reduce(function (acc, item) {
    var value = innerOptions[item];
    acc[item] = _typeof__default["default"](value) === 'object' ? JSON.stringify(value) : value;
    return acc;
  }, {});
  return innerOptions;
}
function aegisReportInfoV2(mAegisV2, options) {
  var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
  if (!mAegisV2 || !options || !method) return;
  try {
    var innerOptions = parseOptions(options, 'msg');
    mAegisV2[method](Object.assign({}, innerOptions));
  } catch (err) {
    console.log('[reportInfo] error', err);
  }
}
function aegisReportErrorV2(mAegisV2, options) {
  return aegisReportInfoV2(mAegisV2, options, 'error');
}
function aegisReportV2(mAegisV2, options) {
  return aegisReportInfoV2(mAegisV2, options, 'report');
}
function aegisReportEventV2(mAegisV2, options) {
  if (!mAegisV2 || !options) return;
  try {
    var innerOptions = parseOptions(options, 'name');
    if (!innerOptions.name) return;
    mAegisV2.reportEvent(Object.assign({}, innerOptions));
  } catch (err) {
    console.log('[reportEvent] error', err);
  }
}

exports.aegisReportErrorV2 = aegisReportErrorV2;
exports.aegisReportEventV2 = aegisReportEventV2;
exports.aegisReportInfoV2 = aegisReportInfoV2;
exports.aegisReportV2 = aegisReportV2;
