/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../core/Error.js";import e from"./summaryStatistics.js";import{getAgeExpressions as a,verifyDates as i,supportedAgeUnits as r}from"./support/ageUtils.js";import{createLayerAdapter as s,featureCapableLayerTypes as n,getLayerTypeLabels as m}from"../support/adapters/support/layerUtils.js";async function o(e){if(!(e&&e.layer&&e.startTime&&e.endTime&&e.unit))throw new t("summary-statistics-for-age:missing-parameters","'layer', 'startTime', 'endTime' and 'unit' parameters are required");const{layer:a,...o}=e,l=s(a,n);if(!l)throw new t("summary-statistics-for-age:invalid-parameters","'layer' must be one of these types: "+m(n).join(", "));const u={layerAdapter:l,...o},p=u.view,y=null!=u.signal?{signal:u.signal}:null;await Promise.all([p?.when(),l.load(y)]);const c=i(l,u.startTime,u.endTime,"summary-statistics-for-age:invalid-parameters");if(c)throw c;if(!u.unit||!r.includes(u.unit))throw new t("summary-statistics-for-age:invalid-parameters",`Supported units are: ${r.join(", ")}`);return u}async function l(t){const{layerAdapter:i,...r}=await o(t),{view:s,startTime:n,endTime:m,unit:l,minValue:u,maxValue:p,signal:y,filter:c,outStatisticTypes:f}=r,{valueExpression:d,statisticsQuery:w}=a({layer:i,startTime:n,endTime:m,unit:l}),T={layer:i,valueExpression:d,...w,minValue:u,maxValue:p,outStatisticTypes:f,view:s,filter:c,signal:y};return e(T)}export{l as default};
