function _slicedToArray(r,n){return _arrayWithHoles(r)||_iterableToArrayLimit(r,n)||_unsupportedIterableToArray(r,n)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,n){var t;if(r)return"string"==typeof r?_arrayLikeToArray(r,n):"Map"===(t="Object"===(t={}.toString.call(r).slice(8,-1))&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,n):void 0}function _arrayLikeToArray(r,n){(null==n||n>r.length)&&(n=r.length);for(var t=0,e=Array(n);t<n;t++)e[t]=r[t];return e}function _iterableToArrayLimit(r,n){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,o,u,a,c=[],i=!0,l=!1;try{if(u=(t=t.call(r)).next,0===n){if(Object(t)!==t)return;i=!1}else for(;!(i=(e=u.call(t)).done)&&(c.push(e.value),c.length!==n);i=!0);}catch(r){l=!0,o=r}finally{try{if(!i&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}function _arrayWithHoles(r){if(Array.isArray(r))return r}(()=>{function r(c,i,l,t){var o="user/";function u(){return t.current().then(function(r){r=r.tenant;return l.url("".concat(o+r,"/groups"))})}function e(r){var n=r.id||r;return t.current().then(function(r){r=r.tenant;return l.url("".concat(o+r,"/groups/").concat(n))})}function a(r,n){return e(r).then(function(r){return"".concat(r,"/users").concat(n?"/".concat(encodeURIComponent(n.id||n)):"")})}function f(r){return e(r).then(function(r){return"".concat(r,"/roles")})}function s(r){return e(r).then(function(r){return c.get(r)})}function n(n){var r=1<arguments.length&&void 0!==arguments[1]&&arguments[1],t={headers:l.contentHeaders("group"),params:r?{forceLogout:r}:{}};return e(n).then(function(r){return c.put(r,n,t).then(function(){return n})})}function h(n){var t={headers:l.contentHeaders("group")};return u().then(function(r){return c.post(r,n,t).then(function(r){return s(_slicedToArray(r.headers("location").match(/\d+$/),1)[0]).then(function(r){return r.data})})})}function d(r,n){return t=(n=n).id||n,f(r).then(function(r){return"".concat(r,"/").concat(t)}).then(function(r){return c.delete(r)});var t}return{list:function r(n){var n=l.pageSizeFilter(n),t={params:n},e=l.cleanListCallback("groups",r,n);return u().then(function(r){return c.get(r,t).then(e)})},detail:s,remove:function(r){var n=1<arguments.length&&void 0!==arguments[1]&&arguments[1],t=n?{params:{forceLogout:n}}:{};return e(r).then(function(r){return c.delete(r,t)})},create:h,update:n,save:function(r){return r.id?n(r,1<arguments.length&&void 0!==arguments[1]&&arguments[1]):h(r)},listRoles:function r(n){var n=l.pageSizeFilter(n),t={params:n},e=l.cleanListCallback("roles",r,n);return i.when(l.url("".concat(o,"roles"))).then(function(r){return c.get(r,t).then(e)})},updateGroups:function(t,n){var e=_.get(t,"groups.references",[]).map(function(r){return r.group.id}),o=[];return n.forEach(function(r){var n;-1===e.indexOf(r)&&o.push((r=r,n={user:_.pick(t,["id","self"])},a(r).then(function(r){return c.post(r,n)})))}),e.forEach(function(r){-1===n.indexOf(r)&&o.push(a(r,t).then(function(r){return c.delete(r)}))}),i.all(o)},updateRoles:function(o,n){var u=o.roles.references.map(function(r){return r.role.id}),a=[];return n.forEach(function(r){var n,t,e;-1===u.indexOf(r)&&a.push((n=o,t={self:l.url("user/roles/".concat(r))},e={headers:l.contentHeaders("roleReference")},f(n).then(function(r){return c.post(r,{role:t},e)})))}),u.forEach(function(r){-1===n.indexOf(r)&&a.push(d(o,r))}),i.all(a)}}}r.$inject=["$http","$q","c8yBase","c8yUser"],angular.module("c8y.core").factory("c8yUserGroup",r)})();