/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import t from"../../../request.js";import{urlToObject as o,join as r}from"../../../core/urlUtils.js";import{normalizeCentralMeridian as i}from"../../../geometry/support/normalizeUtils.js";import{mapParameters as e}from"../../operations/urlUtils.js";import{queryLikeToQueryStringParameters as s}from"./queryUtils.js";function n(t){const o=s(t),r=o.outPivots;if(r?.length){for(const t of r)"Pivot"===t.pivotType&&t.pivotParameters.outStatistic?t.pivotParameters.outStatistic=JSON.stringify(t.pivotParameters.outStatistic):"Unpivot"===t.pivotType&&(t.unPivotParameters.sourceFields=t.unPivotParameters.sourceFields.join(","));o.outPivots=JSON.stringify(r)}return o}async function u(t,o,r){return await a(t,o,r)}async function a(s,u,a={}){const m="string"==typeof s?o(s):s,p=u.geometry?[u.geometry]:[],l=await i(p,null,{signal:a.signal}),c=l?.[0];null!=c&&((u=u.clone()).geometry=c);const y=e({...m.query,f:"json",...n(u)});return t(r(m.path,"queryPivot"),{...a,query:{...y,...a.query}})}export{u as executePivotQuery,n as queryToQueryStringParameters};
