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 n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,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 n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function e(u,r,o,e,a,n){var i,t="tenant/",p="".concat(t,"tenants"),c="".concat(t,"currentTenant"),l="management",s=["applications","ownedApplications","adminName","adminEmail"],f=["allowCreateTenants"],y=["adminPass"],b=o.cleanFields;return{list:function e(t){t=o.pageSizeFilter(_objectSpread(_objectSpread({},t),{},{pageSize:1e3,currentPage:_.get(t,"currentPage")}));var n={params:t};var r=o.url(p);t=o.cleanListCallback("tenants",e,t);return u.get(r,n).then(t)},save:function(e){var e=_.cloneDeep(e),n=!e.applications,t=n?"post":"put",a=e.allowCreateTenants;e.adminPass||(e=b(e,y));e=b(e,n?f:s);var i=o.url(p)+(n?"":"/".concat(e.id)),c={headers:o.contentHeaders("tenant",!0)};return e=b(e,["id"]),r.resolve(e).then(function(e){return u[t](i,e,c)}).then(function(e){var t=r.resolve(e);return t=n&&a?t.then(function(e){var t=e,n=i,r=c,o=a;return t=e.data.id,n="".concat(n,"/").concat(t),u.put(n,{allowCreateTenants:o},r)}).then(function(){return e}):t})},remove:function(e){e=d(e);return u.delete(e)},detail:function(e){e=d(e);return u.get(e)},addApplication:function(e,t,n){var r=t.id||t,e=m(e),r={application:{id:r,self:t.self}},t=_objectSpread({headers:o.contentHeaders("applicationReference",!0)},n);return u.post(e,r,t)},removeApplication:function(e,t,n){t=t.id||t,e="".concat(m(e),"/").concat(t);return u.delete(e,n)},isCurrentUserTopTenant:function(){return e.current().then(function(e){return v(e.tenant)})},isParentTopTenant:function(e){return v(e.parent)},isTopTenant:v,current:function(){var e=0<arguments.length&&void 0!==arguments[0]&&arguments[0],t=n.has("c8yAppStateService")&&n.get("c8yAppStateService");!i&&!e&&t&&t.currentTenant.value&&(i=r.resolve(t.currentTenant.value));i&&!e||(i=u.get(o.url(c),{silentError:!0}).then(o.getResData,function(e){return 404===e.status?r.when({allowsCreateSubtenant:!0}):r.reject(e)}));return i},isEnterpriseEditionTenant:function(){var t={name:"feature-branding"},n=[{name:"sslmanagement"},{name:"feature-user-hierarchy"},{name:"feature-broker"}];return a.areAllAvailable([{name:"branding"}].concat(n)).then(function(e){return e||a.areAllAvailable([t].concat(n))})},isSubscribed:function(t){return this.current().then(function(e){return _.get(e,"applications.references",[]).map(function(e){return e.application})}).then(function(e){return a.isAppOnTheList(e,t)})}};function d(e){e=e.id||e;return o.url("".concat(p,"/").concat(e))}function m(e){return"".concat(d(e),"/applications")}function v(e){return e===l}}e.$inject=["$http","$q","c8yBase","c8yUser","c8yApplication","$injector"],angular.module("c8y.core").factory("c8yTenant",e)})();