/*
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","../../../../../../core/has","../../../../../../core/maybe","../../../../../../core/workers/Connection","../../../../../../geometry/support/quantizationUtils","../../../../../../layers/graphics/featureConversionUtils","../../../../../../layers/ogc/ogcFeatureUtils","../../../../../../rest/query/operations/query","../../support/FeatureSetReaderJSON","../../support/FeatureSetReaderPBF"],(function(e,t,r,n,i,u,o,a,s,c,p){"use strict";let l=function(){function e(e){this.service=e}return e.prototype.destroy=function(){},e}();function y(e){return Array.isArray(e.source)}function f(e){return e&&e.capabilities&&e.collection&&e.layerDefinition}function h(e){const{capabilities:t}=e;return f(e.source)?new z(e):y(e)?new S(e):t.query.supportsFormatPBF&&r("featurelayer-pbf")?new F(e):new v(e)}function d(e){return m.apply(this,arguments)}function m(){return(m=t._asyncToGenerator((function*(e){const t=new i;return yield t.open(e,{}),t}))).apply(this,arguments)}let S=function(e){function r(t){var r;return(r=e.call(this,t)||this)._portsOpen=d(t.source).then((e=>r.client=e)),r}t._inheritsLoose(r,e);var n=r.prototype;return n.destroy=function(){this.client.close(),this.client=null},n.executeQuery=function(){var e=t._asyncToGenerator((function*(e,t){yield this._portsOpen;const r=yield this.client.invoke("queryFeatures",e.toJSON(),t);return c.FeatureSetReaderJSON.fromFeatureSet(r,this.service)}));function r(t,r){return e.apply(this,arguments)}return r}(),r}(l),F=function(e){function r(){return e.apply(this,arguments)||this}return t._inheritsLoose(r,e),r.prototype.executeQuery=function(){var e=t._asyncToGenerator((function*(e,t){const{data:r}=yield s.executeQueryPBFBuffer(this.service.source,e,t),n=!e.quantizationParameters;return p.FeatureSetReaderPBF.fromBuffer(r,this.service,n)}));function r(t,r){return e.apply(this,arguments)}return r}(),r}(l),v=function(e){function r(){return e.apply(this,arguments)||this}return t._inheritsLoose(r,e),r.prototype.executeQuery=function(){var e=t._asyncToGenerator((function*(e,t){const{source:r,capabilities:i,spatialReference:a,objectIdField:p,geometryType:l}=this.service;if(n.isSome(e.quantizationParameters)&&!i.query.supportsQuantization){const i=e.clone(),l=u.toQuantizationTransform(n.unwrap(i.quantizationParameters));i.quantizationParameters=null;const{data:y}=yield s.executeQuery(r,i,a,t),f=o.convertFromFeatureSet(y,p);return o.quantizeOptimizedFeatureSet(l,f),c.FeatureSetReaderJSON.fromOptimizedFeatureSet(f,this.service)}const{data:y}=yield s.executeQuery(r,e,this.service.spatialReference,t);var f;"esriGeometryPoint"===l&&(y.features=null==(f=y.features)?void 0:f.filter((e=>{if(n.isSome(e.geometry)){const t=e.geometry;return Number.isFinite(t.x)&&Number.isFinite(t.y)}return!0})));return c.FeatureSetReaderJSON.fromFeatureSet(y,this.service)}));function r(t,r){return e.apply(this,arguments)}return r}(),r}(l),z=function(e){function r(){return e.apply(this,arguments)||this}return t._inheritsLoose(r,e),r.prototype.executeQuery=function(){var e=t._asyncToGenerator((function*(e,t){const{capabilities:r}=this.service;if(e.quantizationParameters&&!r.query.supportsQuantization){const r=e.clone(),i=u.toQuantizationTransform(n.unwrap(r.quantizationParameters));r.quantizationParameters=null;const s=yield a.queryOptimizedFeatureSet(this.service.source,e,t);return o.quantizeOptimizedFeatureSet(i,s),c.FeatureSetReaderJSON.fromOptimizedFeatureSet(s,this.service)}const i=yield a.queryOptimizedFeatureSet(this.service.source,e,t);return c.FeatureSetReaderJSON.fromOptimizedFeatureSet(i,this.service)}));function r(t,r){return e.apply(this,arguments)}return r}(),r}(l);e.SourceAdapter=l,e.createSourceAdapter=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
