"use strict";

var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
_Object$defineProperty(exports, "__esModule", {
  value: true
});
exports.getMetricManager = exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
var _constants = require("../CallingClient/constants");
var _types = require("../common/types");
var _types2 = require("./types");
var _Logger = _interopRequireDefault(require("../Logger"));
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
var metricManager;

/**
 *
 */
var MetricManager = /*#__PURE__*/function () {
  /**
   * @param webex - Webex object used to send metrics.
   * @param indicator - Service Indicator.
   */
  function MetricManager(webex, indicator) {
    (0, _classCallCheck2.default)(this, MetricManager);
    (0, _defineProperty2.default)(this, "webex", void 0);
    (0, _defineProperty2.default)(this, "deviceInfo", void 0);
    (0, _defineProperty2.default)(this, "serviceIndicator", void 0);
    _Logger.default.info('Initializing metric manager...', {
      file: _constants.METRIC_FILE
    });
    this.webex = webex;
    this.serviceIndicator = indicator;
  }
  return (0, _createClass2.default)(MetricManager, [{
    key: "submitConnectionMetrics",
    value: function submitConnectionMetrics(name, metricAction, type, downTimestamp, upTimestamp) {
      var _this$deviceInfo, _this$deviceInfo$devi, _this$deviceInfo2, _this$deviceInfo2$dev, _this$deviceInfo3, _this$deviceInfo3$dev;
      var metricData = {
        tags: {
          metricAction: metricAction,
          device_id: (_this$deviceInfo = this.deviceInfo) === null || _this$deviceInfo === void 0 ? void 0 : (_this$deviceInfo$devi = _this$deviceInfo.device) === null || _this$deviceInfo$devi === void 0 ? void 0 : _this$deviceInfo$devi.deviceId,
          service_indicator: this.serviceIndicator
        },
        fields: {
          device_url: (_this$deviceInfo2 = this.deviceInfo) === null || _this$deviceInfo2 === void 0 ? void 0 : (_this$deviceInfo2$dev = _this$deviceInfo2.device) === null || _this$deviceInfo2$dev === void 0 ? void 0 : _this$deviceInfo2$dev.clientDeviceUri,
          mobius_url: (_this$deviceInfo3 = this.deviceInfo) === null || _this$deviceInfo3 === void 0 ? void 0 : (_this$deviceInfo3$dev = _this$deviceInfo3.device) === null || _this$deviceInfo3$dev === void 0 ? void 0 : _this$deviceInfo3$dev.uri,
          calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
          downTimestamp: downTimestamp,
          upTimestamp: upTimestamp
        },
        type: type
      };
      if (metricData) {
        this.webex.internal.metrics.submitClientMetrics(name, metricData);
      }
    }
  }, {
    key: "submitUploadLogsMetric",
    value: function submitUploadLogsMetric(name, action, type, trackingId, feedbackId, correlationId, stack, callId, broadworksCorrelationInfo) {
      var _this$deviceInfo4, _this$deviceInfo4$dev, _this$deviceInfo5, _this$deviceInfo5$dev, _this$deviceInfo6, _this$deviceInfo6$dev;
      var data;
      var commonData = {
        tags: {
          action: action,
          device_id: (_this$deviceInfo4 = this.deviceInfo) === null || _this$deviceInfo4 === void 0 ? void 0 : (_this$deviceInfo4$dev = _this$deviceInfo4.device) === null || _this$deviceInfo4$dev === void 0 ? void 0 : _this$deviceInfo4$dev.deviceId,
          service_indicator: this.serviceIndicator
        },
        fields: {
          device_url: (_this$deviceInfo5 = this.deviceInfo) === null || _this$deviceInfo5 === void 0 ? void 0 : (_this$deviceInfo5$dev = _this$deviceInfo5.device) === null || _this$deviceInfo5$dev === void 0 ? void 0 : _this$deviceInfo5$dev.clientDeviceUri,
          mobius_url: (_this$deviceInfo6 = this.deviceInfo) === null || _this$deviceInfo6 === void 0 ? void 0 : (_this$deviceInfo6$dev = _this$deviceInfo6.device) === null || _this$deviceInfo6$dev === void 0 ? void 0 : _this$deviceInfo6$dev.uri,
          calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
          correlation_id: correlationId,
          broadworksCorrelationInfo: broadworksCorrelationInfo,
          tracking_id: trackingId,
          feedback_id: feedbackId,
          call_id: callId
        },
        type: type
      };
      switch (name) {
        case _types2.METRIC_EVENT.UPLOAD_LOGS_SUCCESS:
          {
            data = commonData;
            break;
          }
        case _types2.METRIC_EVENT.UPLOAD_LOGS_FAILED:
          {
            data = _objectSpread(_objectSpread({}, commonData), {}, {
              fields: _objectSpread(_objectSpread({}, commonData.fields), {}, {
                error: stack
              })
            });
            break;
          }
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }

    /**
     * @param deviceInfo - DeviceInfo object.
     */
  }, {
    key: "setDeviceInfo",
    value: function setDeviceInfo(deviceInfo) {
      this.deviceInfo = deviceInfo;
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param region - Region string.
     * @param trackingId - Tracking ID string.
     */
  }, {
    key: "submitRegionInfoMetric",
    value: function submitRegionInfoMetric(name, metricAction, type, mobiusHost, clientRegion, countryCode, trackingId) {
      var _this$deviceInfo7, _this$deviceInfo7$dev, _this$deviceInfo8, _this$deviceInfo8$dev, _this$deviceInfo9, _this$deviceInfo9$dev;
      var data = {
        tags: {
          action: metricAction,
          device_id: (_this$deviceInfo7 = this.deviceInfo) === null || _this$deviceInfo7 === void 0 ? void 0 : (_this$deviceInfo7$dev = _this$deviceInfo7.device) === null || _this$deviceInfo7$dev === void 0 ? void 0 : _this$deviceInfo7$dev.deviceId,
          service_indicator: _types.ServiceIndicator.CALLING
        },
        fields: {
          device_url: (_this$deviceInfo8 = this.deviceInfo) === null || _this$deviceInfo8 === void 0 ? void 0 : (_this$deviceInfo8$dev = _this$deviceInfo8.device) === null || _this$deviceInfo8$dev === void 0 ? void 0 : _this$deviceInfo8$dev.clientDeviceUri,
          mobius_url: (_this$deviceInfo9 = this.deviceInfo) === null || _this$deviceInfo9 === void 0 ? void 0 : (_this$deviceInfo9$dev = _this$deviceInfo9.device) === null || _this$deviceInfo9$dev === void 0 ? void 0 : _this$deviceInfo9$dev.uri,
          calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
          mobius_host: mobiusHost,
          client_region: clientRegion,
          country_code: countryCode,
          tracking_id: trackingId
        },
        type: type
      };
      this.webex.internal.metrics.submitClientMetrics(name, data);
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param mobiusServers - Array of Mobius server objects.
     */
  }, {
    key: "submitMobiusServersMetric",
    value: function submitMobiusServersMetric(name, metricAction, type, mobiusServers, trackingId) {
      var _this$deviceInfo0, _this$deviceInfo0$dev, _this$deviceInfo1, _this$deviceInfo1$dev, _this$deviceInfo10, _this$deviceInfo10$de;
      var data = {
        tags: {
          action: metricAction,
          device_id: (_this$deviceInfo0 = this.deviceInfo) === null || _this$deviceInfo0 === void 0 ? void 0 : (_this$deviceInfo0$dev = _this$deviceInfo0.device) === null || _this$deviceInfo0$dev === void 0 ? void 0 : _this$deviceInfo0$dev.deviceId,
          service_indicator: _types.ServiceIndicator.CALLING
        },
        fields: {
          device_url: (_this$deviceInfo1 = this.deviceInfo) === null || _this$deviceInfo1 === void 0 ? void 0 : (_this$deviceInfo1$dev = _this$deviceInfo1.device) === null || _this$deviceInfo1$dev === void 0 ? void 0 : _this$deviceInfo1$dev.clientDeviceUri,
          mobius_url: (_this$deviceInfo10 = this.deviceInfo) === null || _this$deviceInfo10 === void 0 ? void 0 : (_this$deviceInfo10$de = _this$deviceInfo10.device) === null || _this$deviceInfo10$de === void 0 ? void 0 : _this$deviceInfo10$de.uri,
          calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
          primary_mobius_servers_region: mobiusServers.primary.region,
          primary_mobius_servers_uris: mobiusServers.primary.uris.join(','),
          backup_mobius_servers_region: mobiusServers.backup.region,
          backup_mobius_servers_uris: mobiusServers.backup.uris.join(','),
          tracking_id: trackingId
        },
        type: type
      };
      this.webex.internal.metrics.submitClientMetrics(name, data);
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param clientError - Error object used to populate error details in metric.
     */
  }, {
    key: "submitRegistrationMetric",
    value: function submitRegistrationMetric(name, metricAction, type, caller, serverType, trackingId, keepaliveCount, clientError) {
      var data;
      switch (name) {
        case _types2.METRIC_EVENT.REGISTRATION:
          {
            var _this$deviceInfo11, _this$deviceInfo11$de, _this$deviceInfo12, _this$deviceInfo12$de, _this$deviceInfo13, _this$deviceInfo13$de;
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo11 = this.deviceInfo) === null || _this$deviceInfo11 === void 0 ? void 0 : (_this$deviceInfo11$de = _this$deviceInfo11.device) === null || _this$deviceInfo11$de === void 0 ? void 0 : _this$deviceInfo11$de.deviceId,
                service_indicator: this.serviceIndicator
              },
              fields: {
                device_url: (_this$deviceInfo12 = this.deviceInfo) === null || _this$deviceInfo12 === void 0 ? void 0 : (_this$deviceInfo12$de = _this$deviceInfo12.device) === null || _this$deviceInfo12$de === void 0 ? void 0 : _this$deviceInfo12$de.clientDeviceUri,
                mobius_url: (_this$deviceInfo13 = this.deviceInfo) === null || _this$deviceInfo13 === void 0 ? void 0 : (_this$deviceInfo13$de = _this$deviceInfo13.device) === null || _this$deviceInfo13$de === void 0 ? void 0 : _this$deviceInfo13$de.uri,
                calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                reg_source: caller,
                server_type: serverType,
                trackingId: trackingId
              },
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.REGISTRATION_ERROR:
          {
            var _this$deviceInfo14, _this$deviceInfo14$de, _this$deviceInfo15, _this$deviceInfo15$de, _this$deviceInfo16, _this$deviceInfo16$de, _errorData, _errorData2;
            var errorData;
            if (clientError) {
              errorData = {
                msg: clientError.getError().message,
                type: clientError.getError().type
              };
            }
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo14 = this.deviceInfo) === null || _this$deviceInfo14 === void 0 ? void 0 : (_this$deviceInfo14$de = _this$deviceInfo14.device) === null || _this$deviceInfo14$de === void 0 ? void 0 : _this$deviceInfo14$de.deviceId,
                service_indicator: this.serviceIndicator
              },
              fields: {
                device_url: (_this$deviceInfo15 = this.deviceInfo) === null || _this$deviceInfo15 === void 0 ? void 0 : (_this$deviceInfo15$de = _this$deviceInfo15.device) === null || _this$deviceInfo15$de === void 0 ? void 0 : _this$deviceInfo15$de.clientDeviceUri,
                mobius_url: (_this$deviceInfo16 = this.deviceInfo) === null || _this$deviceInfo16 === void 0 ? void 0 : (_this$deviceInfo16$de = _this$deviceInfo16.device) === null || _this$deviceInfo16$de === void 0 ? void 0 : _this$deviceInfo16$de.uri,
                calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                reg_source: caller,
                server_type: serverType,
                trackingId: trackingId,
                error: (_errorData = errorData) === null || _errorData === void 0 ? void 0 : _errorData.msg,
                error_type: (_errorData2 = errorData) === null || _errorData2 === void 0 ? void 0 : _errorData2.type
              },
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.KEEPALIVE_ERROR:
          {
            var _this$deviceInfo17, _this$deviceInfo17$de, _this$deviceInfo18, _this$deviceInfo18$de, _this$deviceInfo19, _this$deviceInfo19$de, _errorData4, _errorData5;
            var _errorData3;
            if (clientError) {
              _errorData3 = {
                msg: clientError.getError().message,
                type: clientError.getError().type
              };
            }
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo17 = this.deviceInfo) === null || _this$deviceInfo17 === void 0 ? void 0 : (_this$deviceInfo17$de = _this$deviceInfo17.device) === null || _this$deviceInfo17$de === void 0 ? void 0 : _this$deviceInfo17$de.deviceId,
                service_indicator: this.serviceIndicator
              },
              fields: {
                device_url: (_this$deviceInfo18 = this.deviceInfo) === null || _this$deviceInfo18 === void 0 ? void 0 : (_this$deviceInfo18$de = _this$deviceInfo18.device) === null || _this$deviceInfo18$de === void 0 ? void 0 : _this$deviceInfo18$de.clientDeviceUri,
                mobius_url: (_this$deviceInfo19 = this.deviceInfo) === null || _this$deviceInfo19 === void 0 ? void 0 : (_this$deviceInfo19$de = _this$deviceInfo19.device) === null || _this$deviceInfo19$de === void 0 ? void 0 : _this$deviceInfo19$de.uri,
                calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                reg_source: caller,
                server_type: serverType,
                trackingId: trackingId,
                keepalive_count: keepaliveCount,
                error: (_errorData4 = _errorData3) === null || _errorData4 === void 0 ? void 0 : _errorData4.msg,
                error_type: (_errorData5 = _errorData3) === null || _errorData5 === void 0 ? void 0 : _errorData5.type
              },
              type: type
            };
            break;
          }
        default:
          _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
            file: _constants.METRIC_FILE,
            method: 'submitRegistrationMetric'
          });
          break;
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param callId - Call ID of the call sending the metric.
     * @param correlationId - Correlation ID of the call sending the metric.
     * @param callError - Error object used to populate error details in metric.
     */
  }, {
    key: "submitCallMetric",
    value: function submitCallMetric(name, metricAction, type, callId, correlationId, callError) {
      var data;
      switch (name) {
        case _types2.METRIC_EVENT.CALL:
          {
            var _this$deviceInfo20, _this$deviceInfo20$de, _this$deviceInfo21, _this$deviceInfo21$de, _this$deviceInfo22, _this$deviceInfo22$de;
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo20 = this.deviceInfo) === null || _this$deviceInfo20 === void 0 ? void 0 : (_this$deviceInfo20$de = _this$deviceInfo20.device) === null || _this$deviceInfo20$de === void 0 ? void 0 : _this$deviceInfo20$de.deviceId,
                service_indicator: this.serviceIndicator
              },
              fields: {
                device_url: (_this$deviceInfo21 = this.deviceInfo) === null || _this$deviceInfo21 === void 0 ? void 0 : (_this$deviceInfo21$de = _this$deviceInfo21.device) === null || _this$deviceInfo21$de === void 0 ? void 0 : _this$deviceInfo21$de.clientDeviceUri,
                mobius_url: (_this$deviceInfo22 = this.deviceInfo) === null || _this$deviceInfo22 === void 0 ? void 0 : (_this$deviceInfo22$de = _this$deviceInfo22.device) === null || _this$deviceInfo22$de === void 0 ? void 0 : _this$deviceInfo22$de.uri,
                calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                call_id: callId,
                correlation_id: correlationId
              },
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.CALL_ERROR:
          {
            if (callError) {
              var _this$deviceInfo23, _this$deviceInfo23$de, _this$deviceInfo24, _this$deviceInfo24$de, _this$deviceInfo25, _this$deviceInfo25$de;
              data = {
                tags: {
                  action: metricAction,
                  device_id: (_this$deviceInfo23 = this.deviceInfo) === null || _this$deviceInfo23 === void 0 ? void 0 : (_this$deviceInfo23$de = _this$deviceInfo23.device) === null || _this$deviceInfo23$de === void 0 ? void 0 : _this$deviceInfo23$de.deviceId,
                  service_indicator: this.serviceIndicator
                },
                fields: {
                  device_url: (_this$deviceInfo24 = this.deviceInfo) === null || _this$deviceInfo24 === void 0 ? void 0 : (_this$deviceInfo24$de = _this$deviceInfo24.device) === null || _this$deviceInfo24$de === void 0 ? void 0 : _this$deviceInfo24$de.clientDeviceUri,
                  mobius_url: (_this$deviceInfo25 = this.deviceInfo) === null || _this$deviceInfo25 === void 0 ? void 0 : (_this$deviceInfo25$de = _this$deviceInfo25.device) === null || _this$deviceInfo25$de === void 0 ? void 0 : _this$deviceInfo25$de.uri,
                  calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                  call_id: callId,
                  correlation_id: correlationId,
                  error: callError.getCallError().message,
                  error_type: callError.getCallError().type
                },
                type: type
              };
            }
            break;
          }
        default:
          _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
            file: _constants.METRIC_FILE,
            method: 'submitCallMetric'
          });
          break;
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param callId - Call ID of the call sending the metric.
     * @param correlationId - Correlation ID of the call sending the metric.
     * @param localSdp - Local SDP information for media metric.
     * @param remoteSdp - Remote SDP information for media metric.
     * @param callError - Error object used to populate error details in metric.
     */
  }, {
    key: "submitMediaMetric",
    value: function submitMediaMetric(name, metricAction, type, callId, correlationId, localSdp, remoteSdp, state, callError) {
      var data;
      switch (name) {
        case _types2.METRIC_EVENT.MEDIA:
          {
            var _this$deviceInfo26, _this$deviceInfo26$de, _this$deviceInfo27, _this$deviceInfo27$de, _this$deviceInfo28, _this$deviceInfo28$de;
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo26 = this.deviceInfo) === null || _this$deviceInfo26 === void 0 ? void 0 : (_this$deviceInfo26$de = _this$deviceInfo26.device) === null || _this$deviceInfo26$de === void 0 ? void 0 : _this$deviceInfo26$de.deviceId,
                service_indicator: this.serviceIndicator
              },
              fields: {
                device_url: (_this$deviceInfo27 = this.deviceInfo) === null || _this$deviceInfo27 === void 0 ? void 0 : (_this$deviceInfo27$de = _this$deviceInfo27.device) === null || _this$deviceInfo27$de === void 0 ? void 0 : _this$deviceInfo27$de.clientDeviceUri,
                mobius_url: (_this$deviceInfo28 = this.deviceInfo) === null || _this$deviceInfo28 === void 0 ? void 0 : (_this$deviceInfo28$de = _this$deviceInfo28.device) === null || _this$deviceInfo28$de === void 0 ? void 0 : _this$deviceInfo28$de.uri,
                calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                call_id: callId,
                correlation_id: correlationId,
                local_media_details: localSdp,
                remote_media_details: remoteSdp,
                state: state
              },
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.MEDIA_ERROR:
          {
            if (callError) {
              var _this$deviceInfo29, _this$deviceInfo29$de, _this$deviceInfo30, _this$deviceInfo30$de, _this$deviceInfo31, _this$deviceInfo31$de;
              data = {
                tags: {
                  action: metricAction,
                  device_id: (_this$deviceInfo29 = this.deviceInfo) === null || _this$deviceInfo29 === void 0 ? void 0 : (_this$deviceInfo29$de = _this$deviceInfo29.device) === null || _this$deviceInfo29$de === void 0 ? void 0 : _this$deviceInfo29$de.deviceId,
                  service_indicator: this.serviceIndicator
                },
                fields: {
                  device_url: (_this$deviceInfo30 = this.deviceInfo) === null || _this$deviceInfo30 === void 0 ? void 0 : (_this$deviceInfo30$de = _this$deviceInfo30.device) === null || _this$deviceInfo30$de === void 0 ? void 0 : _this$deviceInfo30$de.clientDeviceUri,
                  mobius_url: (_this$deviceInfo31 = this.deviceInfo) === null || _this$deviceInfo31 === void 0 ? void 0 : (_this$deviceInfo31$de = _this$deviceInfo31.device) === null || _this$deviceInfo31$de === void 0 ? void 0 : _this$deviceInfo31$de.uri,
                  calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
                  call_id: callId,
                  correlation_id: correlationId,
                  local_media_details: localSdp,
                  remote_media_details: remoteSdp,
                  error: callError.getCallError().message,
                  error_type: callError.getCallError().type
                },
                type: type
              };
            }
            break;
          }
        default:
          _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
            file: _constants.METRIC_FILE,
            method: 'submitMediaMetric'
          });
          break;
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }

    /**
     * @param name - Name of the metric being submitted.
     * @param metricAction - Type of action sent in the metric.
     * @param type - Type of metric.
     * @param messageId - Message identifier of a Voicemail message.
     * @param voicemailError - Error string used to populate error details in metric.
     * @param statusCode - Status code used to populate error details in metric.
     */
  }, {
    key: "submitVoicemailMetric",
    value: function submitVoicemailMetric(name, metricAction, type, messageId, voicemailError, statusCode) {
      var data;
      switch (name) {
        case _types2.METRIC_EVENT.VOICEMAIL:
          {
            var _this$deviceInfo32, _this$deviceInfo32$de, _this$deviceInfo33, _this$deviceInfo33$de;
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo32 = this.deviceInfo) === null || _this$deviceInfo32 === void 0 ? void 0 : (_this$deviceInfo32$de = _this$deviceInfo32.device) === null || _this$deviceInfo32$de === void 0 ? void 0 : _this$deviceInfo32$de.deviceId,
                message_id: messageId
              },
              fields: {
                device_url: (_this$deviceInfo33 = this.deviceInfo) === null || _this$deviceInfo33 === void 0 ? void 0 : (_this$deviceInfo33$de = _this$deviceInfo33.device) === null || _this$deviceInfo33$de === void 0 ? void 0 : _this$deviceInfo33$de.clientDeviceUri,
                calling_sdk_version: typeof process !== 'undefined' && process.env.CALLING_SDK_VERSION ? process.env.CALLING_SDK_VERSION : _constants.VERSION
              },
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.VOICEMAIL_ERROR:
          {
            var _this$deviceInfo34, _this$deviceInfo34$de, _this$deviceInfo35, _this$deviceInfo35$de;
            data = {
              tags: {
                action: metricAction,
                device_id: (_this$deviceInfo34 = this.deviceInfo) === null || _this$deviceInfo34 === void 0 ? void 0 : (_this$deviceInfo34$de = _this$deviceInfo34.device) === null || _this$deviceInfo34$de === void 0 ? void 0 : _this$deviceInfo34$de.deviceId,
                message_id: messageId,
                error: voicemailError,
                status_code: statusCode
              },
              fields: {
                device_url: (_this$deviceInfo35 = this.deviceInfo) === null || _this$deviceInfo35 === void 0 ? void 0 : (_this$deviceInfo35$de = _this$deviceInfo35.device) === null || _this$deviceInfo35$de === void 0 ? void 0 : _this$deviceInfo35$de.clientDeviceUri,
                calling_sdk_version: typeof process !== 'undefined' && process.env.CALLING_SDK_VERSION ? process.env.CALLING_SDK_VERSION : _constants.VERSION
              },
              type: type
            };
            break;
          }
        default:
          _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
            file: _constants.METRIC_FILE,
            method: 'submitVoicemailMetric'
          });
          break;
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }
  }, {
    key: "submitBNRMetric",
    value: function submitBNRMetric(name, type, callId, correlationId) {
      var data;
      if (name === _types2.METRIC_EVENT.BNR_ENABLED || name === _types2.METRIC_EVENT.BNR_DISABLED) {
        var _this$deviceInfo36, _this$deviceInfo36$de, _this$deviceInfo37, _this$deviceInfo37$de, _this$deviceInfo38, _this$deviceInfo38$de;
        data = {
          tags: {
            device_id: (_this$deviceInfo36 = this.deviceInfo) === null || _this$deviceInfo36 === void 0 ? void 0 : (_this$deviceInfo36$de = _this$deviceInfo36.device) === null || _this$deviceInfo36$de === void 0 ? void 0 : _this$deviceInfo36$de.deviceId,
            service_indicator: this.serviceIndicator
          },
          fields: {
            device_url: (_this$deviceInfo37 = this.deviceInfo) === null || _this$deviceInfo37 === void 0 ? void 0 : (_this$deviceInfo37$de = _this$deviceInfo37.device) === null || _this$deviceInfo37$de === void 0 ? void 0 : _this$deviceInfo37$de.clientDeviceUri,
            mobius_url: (_this$deviceInfo38 = this.deviceInfo) === null || _this$deviceInfo38 === void 0 ? void 0 : (_this$deviceInfo38$de = _this$deviceInfo38.device) === null || _this$deviceInfo38$de === void 0 ? void 0 : _this$deviceInfo38$de.uri,
            calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
            call_id: callId,
            correlation_id: correlationId
          },
          type: type
        };
      } else {
        _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
          file: _constants.METRIC_FILE,
          method: 'submitBNRMetric'
        });
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }

    /**
     * @param name - Name of the metric being submitted (MOBIUS_SOCKET or MOBIUS_SOCKET_ERROR).
     * @param metricAction - Type of Mobius WebSocket action.
     * @param type - Type of metric.
     * @param wssUrl - The Mobius WebSocket URL involved in the action.
     * @param trackingId - Tracking ID associated with the operation, if any.
     * @param error - Error string used to populate error details (for MOBIUS_SOCKET_ERROR).
     * @param eventType - Type of async event received over the socket, if applicable.
     */
  }, {
    key: "submitMobiusSocketMetric",
    value: function submitMobiusSocketMetric(name, metricAction, type, wssUrl, trackingId, error, eventType) {
      var _this$deviceInfo39, _this$deviceInfo39$de, _this$deviceInfo40, _this$deviceInfo40$de, _this$deviceInfo41, _this$deviceInfo41$de;
      var data;
      var commonTags = {
        action: metricAction,
        device_id: (_this$deviceInfo39 = this.deviceInfo) === null || _this$deviceInfo39 === void 0 ? void 0 : (_this$deviceInfo39$de = _this$deviceInfo39.device) === null || _this$deviceInfo39$de === void 0 ? void 0 : _this$deviceInfo39$de.deviceId,
        service_indicator: this.serviceIndicator
      };
      var commonFields = {
        device_url: (_this$deviceInfo40 = this.deviceInfo) === null || _this$deviceInfo40 === void 0 ? void 0 : (_this$deviceInfo40$de = _this$deviceInfo40.device) === null || _this$deviceInfo40$de === void 0 ? void 0 : _this$deviceInfo40$de.clientDeviceUri,
        mobius_url: (_this$deviceInfo41 = this.deviceInfo) === null || _this$deviceInfo41 === void 0 ? void 0 : (_this$deviceInfo41$de = _this$deviceInfo41.device) === null || _this$deviceInfo41$de === void 0 ? void 0 : _this$deviceInfo41$de.uri,
        calling_sdk_version: process.env.CALLING_SDK_VERSION || _constants.VERSION,
        wss_url: wssUrl,
        tracking_id: trackingId,
        event_type: eventType
      };
      switch (name) {
        case _types2.METRIC_EVENT.MOBIUS_SOCKET:
          {
            data = {
              tags: commonTags,
              fields: commonFields,
              type: type
            };
            break;
          }
        case _types2.METRIC_EVENT.MOBIUS_SOCKET_ERROR:
          {
            data = {
              tags: commonTags,
              fields: _objectSpread(_objectSpread({}, commonFields), {}, {
                error: error
              }),
              type: type
            };
            break;
          }
        default:
          _Logger.default.warn('Invalid metric name received. Rejecting request to submit metric.', {
            file: _constants.METRIC_FILE,
            method: 'submitMobiusSocketMetric'
          });
          break;
      }
      if (data) {
        this.webex.internal.metrics.submitClientMetrics(name, data);
      }
    }
  }]);
}();
/**
 * @param webex - Webex object to communicate with metrics microservice.
 * @param indicator - Service Indicator.
 */
var getMetricManager = exports.getMetricManager = function getMetricManager(webex, indicator) {
  if (!metricManager && webex) {
    metricManager = new MetricManager(webex, indicator);
  }
  return metricManager;
};
var _default = exports.default = getMetricManager;
//# sourceMappingURL=index.js.map
