/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import s from"../../core/Error.js";import{getSumOfAttributesExpr as t,verifyBasicFieldValidity as e}from"./support/utils.js";import{verifyBinningParams as i}from"../support/binningUtils.js";import{defaultStatisticTypes as r,getFieldsList as a}from"../support/utils.js";import{binningCapableLayerTypes as n,createLayerAdapter as o,getLayerTypeLabels as l}from"../support/adapters/support/layerUtils.js";async function u(t){if(!(t&&t.layer&&t.attributes))throw new s("summary-statistics-for-attributes:missing-parameters","'layer' and 'attributes' parameters are required");if(t.attributes.some(s=>!!s.valueExpression)&&!t.view)throw new s("summary-statistics-for-attributes:missing-parameters","View is required when 'valueExpression' is specified in attributes");t.forBinning&&i(t,"summary-statistics-for-attributes");const{layer:r,...u}=t,p=[2,3,7,4,6,9,15],m=t.forBinning?n:p,c=o(r,m,t.forBinning);if(!c)throw new s("summary-statistics-for-attributes:invalid-parameters","'layer' must be one of these types: "+l(m).join(", "));const f={layerAdapter:c,...u};f.includeZeros=null==f.includeZeros||f.includeZeros,f.includeNegatives=null==f.includeNegatives||f.includeNegatives;const d=f.view,y=null!=f.signal?{signal:f.signal}:null;await Promise.all([d?.when(),c.load(y)]);const w=[];for(const s of f.attributes){const t=await a({field:s.field,valueExpression:s.valueExpression});Array.prototype.push.apply(w,t)}const v=e(c,w,"summary-statistics-for-attributes:invalid-parameters");if(v)throw v;return f}async function p(s){const{layerAdapter:e,...i}=await u(s),a=t(i.attributes,i.includeZeros,i.includeNegatives);return e.summaryStatistics({valueExpression:a.valueExpression,sqlExpression:a.sqlExpression,sqlWhere:a.sqlWhere,view:i.view,filter:i.filter,outStatisticTypes:r,signal:i.signal})}export{p as default};
