angular.module("c8y.core").factory("c8yQueriesUtil",function(){var c={__not:function(n){return["not(",l(n,null),")"].join("")},__and:function(n){return l(n,null,"and")},__or:function(n){return l(n,null,"or")},__eq:function(n,r){return _.isObjectLike(n)?l(n,r):[r,"eq",i(n)].join(" ")},__gt:function(n,r){return[r,"gt",i(n)].join(" ")},__ge:function(n,r){return[r,"ge",i(n)].join(" ")},__lt:function(n,r){return[r,"lt",i(n)].join(" ")},__le:function(n,r){return[r,"le",i(n)].join(" ")},__in:function(n,r){return f(_.map(_.filter(n,_.identity),function(n){return[r,"eq",i(n)].join(" ")}),"or")},__bygroupid:function(n){return["bygroupid(",n,")"].join("")},__has:function(n){return["has(",n,")"].join("")}};function f(n,r){return 1<n.length?["(",n.join(") ".concat(r," (")),")"].join(""):n[0]}function i(n){return _.isString(n)?["'",n,"'"].join(""):n}function l(n,r,i){var t,u=r||null,o=i||"and",e=[];return _.isArray(n)?_.forOwn(n,function(n){n=l(n,null,o);_.isEmpty(n)||e.push(n)}):_.forOwn(n,function(n,r){t=_.isUndefined(c[r])?c.__eq(n,r):c[r](n,u),_.isEmpty(t)||e.push(t)}),f(e,o)}function t(n){var i=[];return _.forOwn(n,function(n){_.forOwn(n,function(n,r){0!==n&&i.push([r,0<n?"asc":"desc"].join(" "))})}),i.join(",")}return{buildQuery:function(n){var r=[],i=l(n.__filter||n),n=t(n.__orderby);return _.isEmpty(i)||r.push(["$filter=(",i,")"].join("")),_.isEmpty(n)||r.push(["$orderby=",n].join("")),r.join(" ")},buildQueryFilter:l,buildQueryOrderby:t}});