function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ownKeys(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);r=r.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function e(i,e,o,r,n,t,c){var u=["target","min","max","yellowRangeMin","yellowRangeMax","redRangeMin","redRangeMax"];function a(){return r.list({fragmentType:"c8y_Kpi",pageSize:c.MAX_PAGESIZE})}return{list:a,listByIds:function(t){return a().then(function(e){return t&&t.length?_.filter(e,function(e){return-1<t.indexOf(e.id)}):e})},detail:function(e){return r.detail(e).then(function(e){var t=e.data.c8y_Kpi;return _.forEach(u,function(e){_.isUndefined(t[e])||(t[e]=parseFloat(t[e]),Number.isNaN(Number(t[e]))&&delete t[e])}),e})},remove:r.remove,save:function(e){return delete(e=_.cloneDeep(e))._measurement,e.c8y_Global={},r.save(e)},listKpiForDevice:function(e){var t=e.id||e;return r.getSupportedSeries(t).then(function(e){return i.all({kpis:(n=c.url("inventory/managedObjects/".concat(t,"/kpis")),r()),series:e});function r(e){var t={params:e=_.assign({pageSize:c.MAX_PAGESIZE},e)},e=c.cleanListCallback("managedObjects",r,e);return o.get(n,t).then(e)}var n}).then(function(e){var r=e.kpis,t=e.series;return{matchKpi:_.filter(r,function(e){return _.find(t,{fragment:e.c8y_Kpi.fragment,series:e.c8y_Kpi.series})}),nonKpiSeries:_.filter(t,function(t){return!_.find(r,function(e){return e.c8y_Kpi.fragment===t.fragment&&e.c8y_Kpi.series===t.series})})}})},getMeasurement:function(e,t){var r=e.c8y_Kpi||e,e=_objectSpread(_objectSpread({},c.timeOrderFilter()),{},{source:t,valueFragmentType:r.fragment,valueFragmentSeries:r.series,pageSize:1,revert:!0});return n.list(e).then(_.head).then(function(e){return function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _objectSpread({kpi:e,time:t.time,source:t.source},_.get(t,e.fragment,{}))}(r,e)})}}}e.$inject=["$q","$log","$http","c8yInventory","c8yMeasurements","c8yUser","c8yBase"],angular.module("c8y.core").factory("c8yKpi",e)})();