(()=>{function t(n,t,e,r,i,o,a,c,s){var u={getThisMonth:function(){var t=e.monthFilter();return _.unset(t,"dataTo"),m(t)},getLastMonth:function(){return m(e.monthFilter({},1))},getThisDay:function(){return{dateFrom:moment().startOf("day").format("YYYY-MM-DD")}},getTerminalUsage:function(t){1<arguments.length&&void 0!==arguments[1]&&arguments[1]&&d.cache.delete(t);return d(t)},getUsageTooltip:function(t,e,n){var r=[];_.isUndefined(t)||(o={thisMonthEnd:t.dateTo,thisMonthStart:t.dateFrom},r.push(i.getString("Usage in this month to date ({{thisMonthStart}} - {{thisMonthEnd}})",o)));{var o;_.isUndefined(n)||(o={thisMonthEnd:t.dateTo,thisMonthStart:t.dateFrom,lastMonthStart:e.dateFrom,lastMonthEnd:e.dateTo,lastMonthUsage:n},r.push(i.getString("Usage in the last month ({{lastMonthStart}} - {{lastMonthEnd}}): {{lastMonthUsage}}",o)))}return r.join("\n")},getTodaysUsageTooltip:function(){return t("Recent data")},processUsageData:function(t,n){t=t?_.reduce(t,function(t,e){return t+_.get(e,n)},0).toFixed(3):0;return 0<t?t:0},isAdmin:g,getProviderSupportedFunctionalities:l,getCurrentProviderDetails:f,getThisDayDataUsage:function(t,e){2<arguments.length&&void 0!==arguments[2]&&arguments[2]&&h.cache.delete("".concat(t,"_").concat(e));return h(t,e)},shouldShowConnectivityTabInDM:function(t){return c.detailCached(t).then(e.getResData).then(M).then(y).then(o.ping).then(o.isConnectivitySubscribed).then(_.constant(!0)).catch(_.constant(!1))},isDeviceSupportedByCurrentProvider:function(t){return o.getTerminalDetails(t,{},{},{silentError:!0}).catch(function(t){return 400!==t.status&&s.danger(e.getResErrorMessage(t)),n.reject(t)})},checkConnectivityCache:function(t){return c.detailCached(t).then(e.getResData).then(function(e){return _.get(e,"c8y_Mobile.c8y_IsConnectivity")?n.when():o.getTerminalDetails(t,{},{},{silentError:!0}).then(function(){return _.set(e,"c8y_Mobile.c8y_IsConnectivity",{}),r.canAdminMOs([e]).then(function(t){return t?c.save(e):n.when(e)})})})}},h=_.memoize(function(t,e){return o.getTerminalDataUsage(t,{},e)},function(t,e){return"".concat(t,"_").concat(e)}),d=_.memoize(function(t){return o.getTerminalUsage(t,{},{})});return u;function m(t){var e;return t.dateFrom&&(e=t.dateFrom,t.dateFrom=moment(e).format("YYYY-MM-DD"),t.cycleStartDate=moment(e).format("YYYY-MM-DD")),t.dateTo=(t.dateTo?moment(t.dateTo):moment()).format("YYYY-MM-DD"),t}function g(){return g.promise=g.promise?g.promise:r.hasAnyRole(["ROLE_CONNECTIVITY_ADMIN"])}function l(){return l.promise=l.promise?l.promise:o.getProviderSupportedFunctionalities().then(function(t){t=t.functionalities;return _.reduce(t,function(t,e){return t[e]=!0,t},{})})}function f(){return f.promise=f.promise?f.promise:a.detail()}function y(){return r.hasAnyRole(["ROLE_CONNECTIVITY_READ"]).then(function(t){return t?n.when():n.reject()})}function M(t){return _.get(t,"c8y_Mobile.iccid")||_.get(t,"c8y_Mobile.msisdn")?n.when():n.reject()}}t.$inject=["$q","gettext","c8yBase","c8yPermissions","gettextCatalog","c8yConnectivity","c8yConnectivitySettings","c8yDevices","c8yAlert"],angular.module("c8y.connectivityV2").factory("connectivityService",t)})();