/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../core/Error","../../core/maybe","./support/utils","../support/utils","../support/adapters/support/layerUtils"],(function(e,r,t,s,i,a){"use strict";function n(e){return u.apply(this,arguments)}function u(){return(u=e._asyncToGenerator((function*(e){if(!(e&&e.layer&&e.attributes))throw new r("summary-statistics-for-attributes:missing-parameters","'layer' and 'attributes' parameters are required");if(e.attributes.some((e=>!!e.valueExpression))&&!e.view)throw new r("summary-statistics-for-attributes:missing-parameters","View is required when 'valueExpression' is specified in attributes");const n=[a.LayerType.CSVLayer,a.LayerType.FeatureLayer,a.LayerType.OGCFeatureLayer,a.LayerType.GeoJSONLayer,a.LayerType.WFSLayer],{layer:u,...l}=e,o=a.createLayerAdapter(u,n),p={layerAdapter:o,...l};if(p.includeZeros=null==p.includeZeros||p.includeZeros,p.includeNegatives=null==p.includeNegatives||p.includeNegatives,!o)throw new r("summary-statistics-for-attributes:invalid-parameters","'layer' must be one of these types: "+a.getLayerTypeLabels(n).join(", "));const y=p.view,c=t.isSome(p.signal)?{signal:p.signal}:null;yield Promise.all([y&&y.when(),o.load(c)]);const d=[];for(const r of p.attributes){const e=yield i.getFieldsList({field:r.field,valueExpression:r.valueExpression});Array.prototype.push.apply(d,e)}const f=s.verifyBasicFieldValidity(o,d,"summary-statistics-for-attributes:invalid-parameters");if(f)throw f;return p}))).apply(this,arguments)}function l(e){return o.apply(this,arguments)}function o(){return(o=e._asyncToGenerator((function*(e){const{layerAdapter:r,...t}=yield n(e),i=s.getSumOfAttributesExpr(t.attributes,t.includeZeros,t.includeNegatives);return r.summaryStatistics({valueExpression:i.valueExpression,sqlExpression:i.sqlExpression,sqlWhere:i.sqlWhere,view:t.view,signal:t.signal})}))).apply(this,arguments)}return l}));
