/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../core/Error.js";import{verifyBasicFieldValidity as i,verifyFilterValidity as s}from"./support/utils.js";import{verifyBinningParams as r}from"../support/binningUtils.js";import{getFieldsList as a}from"../support/utils.js";import{binningCapableLayerTypes as n,createLayerAdapter as t,getLayerTypeLabels as l,defaultSupportedLayerTypes as o}from"../support/adapters/support/layerUtils.js";async function u(u){if(!u?.layer||!u.field&&!u.valueExpression)throw new e("unique-values:missing-parameters","'layer' and 'field' or 'valueExpression' parameters are required");const p=u.valueExpression||u.sqlExpression,f=p&&!u.sqlExpression;if(p)if(f){if(!u.view)throw new e("unique-values:missing-parameters","View is required when 'valueExpression' is specified")}else if(!u.valueExpression)throw new e("unique-values:missing-parameters","'valueExpression' parameters are required");u.forBinning&&r(u,"unique-values");const{layer:m,...d}=u,v=[...o,5],w=u.forBinning?n:v,c=t(m,w,u.forBinning);if(!c)throw new e("unique-values:invalid-parameters","'layer' must be one of these types: "+l(w).join(", "));const q={layerAdapter:c,...d},x=null!=q.signal?{signal:q.signal}:null;await c.load(x);const y=await a({field:q.field,field2:q.field2,field3:q.field3,valueExpression:q.valueExpression}),E=i(c,y,"unique-values:invalid-parameters");if(E)throw E;q.filter&&!q.filter.spatialRelationship&&(q.filter.spatialRelationship="intersects");const g=s(q.filter,"summary-statistics:invalid-parameters");if(g)throw g;return q}async function p(e){const{layerAdapter:i,...s}=await u(e);return i.uniqueValues(s)}export{p as default};
