/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/jsonMap","../../../core/maybe","../../../core/unitUtils","../../../geometry/support/extentUtils","../../../geometry/support/jsonUtils","../../../geometry/support/normalizeUtils","../../../geometry/support/spatialReferenceUtils","../centroid","../featureConversionUtils","../OptimizedGeometry","./projectionSupport"],(function(e,t,r,i,n,o,s,l,u,a,c,y,p,m){"use strict";const f=new i.JSONMap({esriSRUnit_Meter:"meters",esriSRUnit_Kilometer:"kilometers",esriSRUnit_Foot:"feet",esriSRUnit_StatuteMile:"miles",esriSRUnit_NauticalMile:"nautical-miles",esriSRUnit_USNauticalMile:"us-nautical-miles"}),g=Object.freeze({}),d=new p,S=new p,h=new p,G={esriGeometryPoint:y.convertToPoint,esriGeometryPolyline:y.convertToPolyline,esriGeometryPolygon:y.convertToPolygon,esriGeometryMultipoint:y.convertToMultipoint};function R(e,t,r,i=e.hasZ,o=e.hasM){if(n.isNone(t))return null;const s=e.hasZ&&i,l=e.hasM&&o;if(r){const n=y.quantizeOptimizedGeometry(h,t,e.hasZ,e.hasM,"esriGeometryPoint",r,i,o);return y.convertToPoint(n,s,l)}return y.convertToPoint(t,s,l)}function M(e,t,r){return"esriGeometryPolygon"===e.geometryType&&t&&(t.centroid||t.geometry)?(t.centroid||(t.centroid=c.getCentroidOptimizedGeometry(new p,t.geometry,e.hasZ,e.hasM)),R(e,t.centroid,r)):null}function _(e,t,r,i,o,s,l=t,u=r){const a=t&&l,c=r&&u,p=n.isSome(i)?"coords"in i?i:i.geometry:null;if(n.isNone(p))return null;if(o){let i=y.generalizeOptimizedGeometry(S,p,t,r,e,o,l,u);return s&&(i=y.quantizeOptimizedGeometry(h,i,a,c,e,s)),G[e](i,a,c)}if(s){const i=y.quantizeOptimizedGeometry(h,p,t,r,e,s,l,u);return G[e](i,a,c)}return y.removeZMValues(d,p,t,r,l,u),G[e](d,a,c)}function P(e,t,r){return U.apply(this,arguments)}function U(){return(U=r._asyncToGenerator((function*(e,t,r){const{outFields:i,orderByFields:n,groupByFieldsForStatistics:o,outStatistics:s}=e;if(i)for(let l=0;l<i.length;l++)i[l]=i[l].trim();if(n)for(let l=0;l<n.length;l++)n[l]=n[l].trim();if(o)for(let l=0;l<o.length;l++)o[l]=o[l].trim();if(s)for(let l=0;l<s.length;l++)s[l].onStatisticField&&(s[l].onStatisticField=s[l].onStatisticField.trim());return e.geometry&&!e.outSR&&(e.outSR=e.geometry.spatialReference),z(e,t,r)}))).apply(this,arguments)}function z(e,t,r){return O.apply(this,arguments)}function O(){return(O=r._asyncToGenerator((function*(e,t,r){if(!e)return null;let{where:i}=e;if(e.where=i=i&&i.trim(),(!i||/^1 *= *1$/.test(i)||t&&t===i)&&(e.where=null),!e.geometry)return e;let o=yield N(e);if(e.distance=0,e.units=null,"esriSpatialRelEnvelopeIntersects"===e.spatialRel){const{spatialReference:t}=e.geometry;o=s.getGeometryExtent(o),o.spatialReference=t}e.geometry=o,yield m.checkProjectionSupport(o.spatialReference,r);const a=(yield u.normalizeCentralMeridian(l.fromJSON(o)))[0];if(n.isNone(a))throw g;const c=a.toJSON(),y=yield m.project(c,c.spatialReference,r);if(!y)throw g;return y.spatialReference=r,e.geometry=y,e}))).apply(this,arguments)}function N(e){return T.apply(this,arguments)}function T(){return(T=r._asyncToGenerator((function*(e){const{geometry:t,distance:r,units:i}=e;if(null==r||"vertexAttributes"in t)return t;const n=t.spatialReference,s=i?f.fromJSON(i):o.getUnitString(n),l=n&&(a.isGeographic(n)||a.isWebMercator(n))?t:yield m.checkProjectionSupport(n,a.WGS84).then((()=>m.project(t,a.WGS84)));return(yield v())(l.spatialReference,l,r,s)}))).apply(this,arguments)}function v(){return w.apply(this,arguments)}function w(){return(w=r._asyncToGenerator((function*(){return(yield new Promise(((t,r)=>e(["../../../geometry/geometryEngineJSON"],t,r)))).geodesicBuffer}))).apply(this,arguments)}function j(e){return e&&E in e?JSON.parse(JSON.stringify(e,F)):e}const E="_geVersion",F=(e,t)=>e!==E?t:void 0;t.QUERY_ENGINE_EMPTY_RESULT=g,t.cleanFromGeometryEngine=j,t.getCentroid=M,t.getGeometry=_,t.normalizeQuery=P,t.normalizeQueryLike=z,t.transformCentroid=R,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
