/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import t from"../../../request.js";import{urlToObject as e,join as i}from"../../../core/urlUtils.js";import{getJsonType as n}from"../../../geometry/support/jsonTypeUtils.js";import{normalizeCentralMeridian as r}from"../../../geometry/support/normalizeUtils.js";import{srToRESTValue as o,equals as s}from"../../../geometry/support/spatialReferenceUtils.js";import{mapParameters as u}from"../../operations/urlUtils.js";function l(t){const e=t.geometry,i=t.toJSON(),r=i;let u,l,a;if(null!=e&&(l=e.spatialReference,a=o(l),r.geometryType=n(e),r.geometry=JSON.stringify(e),r.inSR=a),i.outSR?(r.outSR=o(i.outSR),u=t.outSpatialReference):e&&(r.outSR=r.inSR,u=l),r.bin&&=JSON.stringify(r.bin),r.quantizationParameters&&=JSON.stringify(r.quantizationParameters),r.outStatistics&&=JSON.stringify(r.outStatistics),r.outTimeReference&&=JSON.stringify(r.outTimeReference),i.timeExtent){const t=i.timeExtent,{start:e,end:n}=t;null==e&&null==n||(r.time=e===n?e:`${e??"null"},${n??"null"}`),delete i.timeExtent}return t.defaultSpatialReference&&s(l,u)&&(r.defaultSR=r.inSR,delete r.inSR,delete r.outSR),r}async function a(t,e,i){return null!=e.timeExtent&&e.timeExtent.isEmpty?{data:{features:[]}}:await m(t,e,i)}async function m(n,o,s={}){const a="string"==typeof n?e(n):n,m=o.geometry?[o.geometry]:[],f=await r(m,null,{signal:s.signal}),y=f?.[0];null!=y&&((o=o.clone()).geometry=y);const p=u({...a.query,f:"json",...l(o)});return t(i(a.path,"queryBins"),{...s,query:{...p,...s.query}})}export{a as executeAttributeBinsQuery,l as queryToQueryStringParameters};
