(()=>{function e(c,s,t){var a="devicecontrol/bulkoperations",n="\\/devicecontrol\\/bulkoperations\\/(\\d+)",r=s.cleanFields,E={headers:s.contentHeaders("bulkOperation")},i=["creationTime","id","self","operations"],l=[],o={SCHEDULED:"SCHEDULED",EXECUTING:"EXECUTING",COMPLETED_WITH_FAILURES:"COMPLETED_WITH_FAILURES",COMPLETED_SUCCESSFULLY:"COMPLETED_SUCCESSFULLY",CANCELLED:"CANCELLED"},e=_.keys(o),u="ACTIVE",C="IN_PROGRESS",L={PENDING:[o.SCHEDULED],EXECUTING:[o.EXECUTING],SUCCESSFUL:[o.COMPLETED_SUCCESSFULLY],FAILED:[o.COMPLETED_WITH_FAILURES,o.CANCELLED]},S={};function D(e){e=e.id||e;return s.url("".concat(a,"/").concat(e))}function d(e,t){e=_.isUndefined(t)?e:_.filter(e,function(e){return _.includes(_.isArray(t)?t:[t],T(e))});return e}function p(e){var t=s.url(a),e=r(e,i),n=_.cloneDeep(E);return c.post(t,e,n).then(U)}function U(e){var t=new RegExp(n),e=e.headers("Location").match(t);return parseInt(e[1],10)}function f(e){var t=s.url("".concat(a,"/").concat(e.id)),e=r(e,i.concat(l)),n=_.cloneDeep(E);return c.put(t,e,n)}function T(e){return"CANCELED"===e.status||"DELETED"===e.status?o.CANCELLED:!e.progress||!e.progress.all||0===e.progress.pending&&0===e.progress.executing&&0===e.progress.successful&&0===e.progress.failed?o.SCHEDULED:e.progress&&e.progress.successful+e.progress.failed<e.progress.all?o.EXECUTING:0<e.progress.failed?o.COMPLETED_WITH_FAILURES:o.COMPLETED_SUCCESSFULLY}function g(e){return L[e]}return S.SCHEDULED={label:t("SCHEDULED"),icon:"calendar",cls:""},S.EXECUTING={label:t("EXECUTING"),icon:"refresh",cls:"text-info"},S.COMPLETED_WITH_FAILURES={label:t("COMPLETED WITH FAILURES"),icon:"exclamation-circle",cls:"text-danger"},S.COMPLETED_SUCCESSFULLY={label:t("COMPLETED SUCCESSFULLY"),icon:"check-circle",cls:"text-success"},S.CANCELLED={label:t("CANCELLED"),icon:"ban",cls:"text-danger"},{list:function e(t,n){var r=s.url(a),t=s.pageSizeNoTotalFilter(t),n={params:t,silentError:n},E=s.cleanListCallback("bulkOperations",e,t);return c.get(r,n).then(E).then(_.partialRight(d,t.status))},detail:function(e){return e=D(e),c.get(e)},create:p,save:function(e){return(e.id?f:p)(e)},update:f,canCancel:function(e){return e=e&&e.status,_.includes([u,C],e)},cancel:function(e){return e.status=o.CANCELLED,e.failureReason=t("Bulk operation cancelled by user."),e=D(e),c.delete(e)},retryFailed:function(e){var t=_.cloneDeep(e);return delete t.groupId,t.failedParentId=e.id,p(t)},status:o,statusList:e,getStatus:T,getStatusStyle:function(e){return e=_.isObjectLike(e)?T(e):e,S[e]},doesMatchSingleOpStatus:function(e,t){return e=_.isObjectLike(e)?T(e):e,t=g(t),_.includes(t,e)},getMappedSingleOpStatus:g}}e.$inject=["$http","c8yBase","gettext"],angular.module("c8y.core").factory("c8yDeviceBulkControl",e)})();