/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../request","../../../core/maybe","../../../core/urlUtils","../../../geometry/support/jsonUtils","../../../geometry/support/normalizeUtils","../../operations/urlUtils","./queryZScale"],(function(e,t,r,n,o,u,i,l,s){"use strict";const y="Layer does not support extent calculation.";function a(e,t){var r,o;const i=e.geometry,l=e.toJSON(),s=l;if(n.isSome(i)&&(s.geometry=JSON.stringify(i),s.geometryType=u.getJsonType(i),s.inSR=i.spatialReference.wkid||JSON.stringify(i.spatialReference)),null!=(r=l.topFilter)&&r.groupByFields&&(s.topFilter.groupByFields=l.topFilter.groupByFields.join(",")),null!=(o=l.topFilter)&&o.orderByFields&&(s.topFilter.orderByFields=l.topFilter.orderByFields.join(",")),l.topFilter&&(s.topFilter=JSON.stringify(s.topFilter)),l.objectIds&&(s.objectIds=l.objectIds.join(",")),l.orderByFields&&(s.orderByFields=l.orderByFields.join(",")),l.outFields&&!(null!=t&&t.returnCountOnly||null!=t&&t.returnExtentOnly||null!=t&&t.returnIdsOnly)?l.outFields.includes("*")?s.outFields="*":s.outFields=l.outFields.join(","):delete s.outFields,l.outSR?s.outSR=l.outSR.wkid||JSON.stringify(l.outSR):i&&l.returnGeometry&&(s.outSR=s.inSR),l.returnGeometry&&delete l.returnGeometry,l.timeExtent){const e=l.timeExtent,{start:t,end:r}=e;null==t&&null==r||(s.time=t===r?t:`${null==t?"null":t},${null==r?"null":r}`),delete l.timeExtent}return s}function p(e,t,r,n){return c.apply(this,arguments)}function c(){return(c=t._asyncToGenerator((function*(e,t,r,n){const o=yield g(e,t,"json",n);return s.applyFeatureSetZUnitScaling(t,r,o.data),o}))).apply(this,arguments)}function d(e,t,r){return m.apply(this,arguments)}function m(){return(m=t._asyncToGenerator((function*(e,t,r){return n.isSome(t.timeExtent)&&t.timeExtent.isEmpty?{data:{objectIds:[]}}:g(e,t,"json",r,{returnIdsOnly:!0})}))).apply(this,arguments)}function f(e,t,r){return F.apply(this,arguments)}function F(){return(F=t._asyncToGenerator((function*(e,t,r){return n.isSome(t.timeExtent)&&t.timeExtent.isEmpty?{data:{count:0,extent:null}}:g(e,t,"json",r,{returnExtentOnly:!0,returnCountOnly:!0}).then((e=>{const t=e.data;if(t.hasOwnProperty("extent"))return e;if(t.features)throw new Error(y);if(t.hasOwnProperty("count"))throw new Error(y);return e}))}))).apply(this,arguments)}function S(e,t,r){return n.isSome(t.timeExtent)&&t.timeExtent.isEmpty?Promise.resolve({data:{count:0}}):g(e,t,"json",r,{returnIdsOnly:!0,returnCountOnly:!0})}function g(e,t,u,s={},y={}){const p="string"==typeof e?o.urlToObject(e):e,c=t.geometry?[t.geometry]:[];return s.responseType="pbf"===u?"array-buffer":"json",i.normalizeCentralMeridian(c,null,s).then((e=>{const i=e&&e[0];n.isSome(i)&&((t=t.clone()).geometry=i);const c=l.mapParameters({...p.query,f:u,...y,...a(t,y)});return r(o.join(p.path,"queryTopFeatures"),{...s,query:{...c,...s.query}})}))}e.executeQueryForTopCount=S,e.executeQueryForTopExtents=f,e.executeQueryForTopIds=d,e.executeTopFeaturesQuery=p,e.queryToQueryStringParameters=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
