(()=>{function e(e,a){var t=this,r=(t.$onInit=function(){_.assign(t,{changes:o,addOrGroup:y,addAndRule:c,remove:m,rules:[],valueTypes:[],isLast:f,resourceDataType:t.resource.dataType})},a.Validation.RuleType),n=a.Validation.ValueType,a=a.Validation.ResourceDataType,u=[a.INTEGER,a.FLOAT,a.TIME],s=[a.INTEGER,a.FLOAT,a.TIME,a.STRING,a.BOOLEAN,a.OBJECTLINK],l=[{type:r.GT,valueTypes:u},{type:r.LT,valueTypes:u},{type:r.EQ,valueTypes:s},{type:r.NEQ,valueTypes:s},{type:r.GTE,valueTypes:u},{type:r.LTE,valueTypes:u}],p=[{resourceTypes:[a.INTEGER,a.FLOAT],valueTypes:[n.NUMBER,n.OBJECTLINK]},{resourceTypes:[a.TIME],valueTypes:[n.DATE,n.OBJECTLINK]},{resourceTypes:[a.STRING,a.OBJECTLINK],valueTypes:[n.STRING,n.REGEX,n.OBJECTLINK]},{resourceTypes:[a.BOOLEAN],valueTypes:[n.STRING,n.OBJECTLINK]}];function i(){var e;t.options=_.filter(l,{valueTypes:[t.resource.dataType]}).map(function(e){return e.type}),t.valueTypes=_.flatten(_.filter(p,{resourceTypes:[t.resource.dataType]}).map(function(e){return e.valueTypes})),(e=_.get(t.mapping,"validation"))&&e.type&&e.arg&&e.type===r.OR&&_.forEach(e.arg,function(e){t.rules.push(e.arg)})}function o(){T()}function T(){var a={type:r.OR,arg:[]};_.map(t.rules,function(e){a.arg.push({type:r.AND,arg:e})}),_.assign(t.mapping,{validation:0<a.arg.length?a:null})}function y(){t.rules.push([v()])}function c(e){if(_.isEmpty(e)&&0===t.rules.length)y();else{for(var a=-1,r=0;r<t.rules.length;r++){var n=t.rules[r];if(_.find(n,e)){a=r;break}}-1<a&&t.rules[a].push(v())}T()}function v(){return{type:_.first(t.options),arg:{valueType:_.first(t.valueTypes),value:void 0}}}function m(a){_.forEach(t.rules,function(e){_.remove(e,a)}),_.remove(t.rules,function(e){return 0===e.length}),t.mappingForm.$setDirty(),T()}function f(e){return _.last(t.rules)===e}e.$watch("vm.mapping.validation",function(){t.rules=[],i()})}e.$inject=["$scope","c8yLwm2m"],angular.module("c8y.lwm2m").component("c8yLwm2mValidationRules",{templateUrl:":::PLUGIN_PATH:::/lwm2mValidationRules/lwm2mValidationRules.html",controller:e,controllerAs:"vm",bindings:{mapping:"=",resource:"<"}})})();