(()=>{function e(e,t,s,a,n,p,l){var m=this;function c(){return e.smartRestTemplateId}function r(){var e=c();e&&a.detail(e).then(function(e){m.template=e,m.requestTemplates=e[a.fragmentType].requestTemplates,m.responseTemplates=e[a.fragmentType].responseTemplates})}function u(e){m.selectedResponseTemplate=e}function o(){m.selectedResponseTemplate=void 0}function T(e){m.selectedRequestTemplate=e}function i(){m.selectedRequestTemplate=void 0}m.$onInit=function(){{var e;c()?r():e=t.$on("$routeChangeSuccess",function(){c()&&(r(),e())})}},m.changeTemplateName=function(e){return m.template.name=e,a.save(_.pick(m.template,["id","name"]),!0).then(function(){p.changeTitle({title:e}),t.templateInputForm.$setPristine(),n.success(l("SmartREST template name successfully changed."))})},m.countRequestTemplates=function(){return m.template&&a.countRequestTemplates(m.template)},m.selectResponseTemplate=u,m.deselectResponseTemplate=o,m.newResponseTemplate=function(){u(a.newResponseTemplate())},m.addResponseTemplate=function(e){var t=_.indexOf(m.template[a.fragmentType].responseTemplates,m.selectedResponseTemplate);-1===t?a.addResponseTemplate(m.template,e):m.template[a.fragmentType].responseTemplates[t]=e;return a.save(_.pick(m.template,["id",a.fragmentType])).then(o).then(_.partial(n.success,l("Response template saved.")))},m.removeResponseTemplate=function(){return a.removeResponseTemplate(m.template,m.selectedResponseTemplate),a.save(_.pick(m.template,["id",a.fragmentType])).then(o).then(_.partial(n.success,l("Response template deleted.")))},m.countResponseTemplates=function(){return m.template&&a.countResponseTemplates(m.template)},m.selectRequestTemplate=T,m.deselectRequestTemplate=i,m.newRequestTemplate=function(){T(a.newRequestTemplate())},m.addRequestTemplate=function(e){var t=_.indexOf(m.template[a.fragmentType].requestTemplates,m.selectedRequestTemplate);-1===t?a.addRequestTemplate(m.template,e):m.template[a.fragmentType].requestTemplates[t]=e;return a.save(_.pick(m.template,["id",a.fragmentType])).then(i).then(_.partial(n.success,l("Message template saved.")))},m.removeRequestTemplate=function(){return a.removeRequestTemplate(m.template,m.selectedRequestTemplate),a.save(_.pick(m.template,["id",a.fragmentType])).then(i).then(_.partial(n.success,l("Message template deleted.")))}}e.$inject=["$routeParams","$scope","c8yBase","c8ySmartRestTemplates","c8yAlert","c8yTitle","gettext"],angular.module("c8y.smartRestEditor").controller("SmartRestTemplateDetailsCtrl",e)})();