/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../../core/Error.js";import{getSourceLayer as s,getDataSeriesInfo as i}from"../../../layers/support/dataSeriesUtils.js";import{createTimeSeriesExpression as t}from"../../../layers/support/timeSeriesUtils.js";import r from"../../statistics/summaryStatistics.js";const a=new Set(["big-integer","double","integer","long","single","small-integer"]);function n(s,i){const t=i.fieldTimeMappings??[],r=[];for(const n of t){const t=n.fieldName;if(!t)throw new e("time-series-summary-statistics:invalid-parameters","Found a time series mapping with an empty 'fieldName'");const o=s.getField(t);if(!o)throw new e("time-series-summary-statistics:invalid-parameters",`Field '${t}' defined in time series '${i.name}' does not exist`);if(!a.has(o.type))throw new e("time-series-summary-statistics:invalid-parameters",`Field '${t}' in time series '${i.name}' has unsupported type '${o.type}'`);r.push(t)}return r}async function o(t){const a=s(t.layer);if(!a)throw new e("time-series-summary-statistics:invalid-parameters","'layer' must support dataSeriesInfos");const o=i(a,t.dataSeriesName);if(!o)throw new e("time-series-summary-statistics:invalid-parameters","'dataSeriesName' is not valid");if("time-series-fields"!==o.type)throw new e("time-series-summary-statistics:invalid-parameters","'dataSeriesName' has unsupported type");const m=n(a,o);return r({layer:t.layer,fields:m,view:t.view,filter:t.filter,signal:t.signal})}function m(r){if(!r.dataSeriesName||!r.layer)return r;const a=s(r.layer);if(!a)throw new e("resolve-data-series-info:invalid-parameters","'layer' must support dataSeriesInfos");const n=i(a,r.dataSeriesName);if(!n)throw new e("resolve-data-series-info:invalid-parameters","'dataSeriesName' is not valid");if("time-series-fields"!==n.type)throw new e("resolve-data-series-info:invalid-parameters","'dataSeriesName' has unsupported type");const o=t(n);r.valueExpression=o;const m=a.dataSeriesInfos?.indexOf(n)??-1;return r.valueExpressionTitle=n.title||`${n.name} ${m}`,"field"in r&&(r.field=null),r}export{o as getTimeSeriesSummaryStatistics,m as resolveDataSeriesInfo};
