/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import r from"../../../../core/Accessor.js";import{neverReached as t}from"../../../../core/compilerUtils.js";import s from"../../../../core/Error.js";import{destroyMaybe as o}from"../../../../core/maybe.js";import{throwIfAborted as i,createAbortError as a}from"../../../../core/promiseUtils.js";import{difference as u}from"../../../../core/SetUtils.js";import{property as l,subclass as c}from"../../../../core/accessorSupport/decorators.js";import{fromFeatureSetJSON as n}from"../../../../layers/graphics/dehydratedFeatures.js";import{queueAutoPriority as y}from"../../../../request/queue.js";import{runQuery as p,executeQuery as d,executeQueryForCount as m}from"../../../../rest/query/operations/query.js";import{PBFDecoder as h}from"../../support/PBFDecoder.js";let f=class extends r{constructor(e){super(e)}get implicitFields(){const e=this.layer.outFields?.includes("*");if(!e)return new Set;const r=new Set(this.layerView.requiredFields),t=new Set(this.layerView.availableFields);return u(t,r)}async queryFeaturesDehydrated(e,r){const{layer:t}=this,s=t.capabilities,o=s?.query?.supportsFormatPBF,u=t.parsedUrl;if(o){null==this._decoder&&(this._decoder=new h(this.controller));const s={sourceSpatialReference:t.spatialReference?.toJSON()??null,applyTransform:!0,maxStringAttributeFields:this.implicitFields,maxStringAttributeLength:g};return p(u,e,"pbf",this._createRequestOptions(r)).then(e=>(i(r),null!=this._decoder?this._decoder.invoke({buffer:e,options:s},r.signal):Promise.reject(a())))}return d(u,e,t.spatialReference,this._createRequestOptions(r)).then(e=>n(e,{maxStringAttributeFields:this.implicitFields,maxStringAttributeLength:g}))}queryFeatureCount(e,r){return m(this.layer.parsedUrl,e,this._createRequestOptions(r))}destroy(){this._decoder=o(this._decoder)}_createRequestOptions(e){return{...y,...e,query:{...this.layer.customParameters,token:this.layer.apiKey,...e?.query}}}};e([l({constructOnly:!0})],f.prototype,"layer",void 0),e([l({constructOnly:!0})],f.prototype,"layerView",void 0),e([l({constructOnly:!0})],f.prototype,"controller",void 0),e([l({readOnly:!0})],f.prototype,"implicitFields",null),f=e([c("esri.views.3d.layers.support.featureTileQuery3D.FeatureTileServiceQuery3D")],f);let F=class extends r{constructor(e){super(e)}queryFeaturesDehydrated(e,r){return this.layer.queryFeatures(e,r)}};e([l({constructOnly:!0})],F.prototype,"layer",void 0),F=e([c("esri.views.3d.layers.support.featureTileQuery3D.FeatureTileOGCServiceQuery3D")],F);let w=class extends r{constructor(e){super(e)}queryFeaturesDehydrated(e,r){return this.layer.source.queryFeaturesJSON(e,r).then(n,t=>{if(t&&"query-features-json:unsupported"===t.name)return this.layer.queryFeatures(e,r);throw t})}queryFeatureCount(e,r){return this.layer.queryFeatureCount(e,r)}};function q(e,r){const{layer:o}=e;switch(o.type){case"feature":switch(o.source.type){case"feature-layer":return new f({layer:o,layerView:e,controller:r});case"memory":return new w({layer:o});case"csv":case"geojson":case"oriented-imagery":case"wfs":case"ogc-feature":case"parquet":break;default:t(o.source.type)}break;case"catalog-footprint":return new f({layer:o,layerView:e,controller:r});case"csv":case"geojson":case"oriented-imagery":case"wfs":return new w({layer:o});case"ogc-feature":return new F({layer:o})}throw new s("feature-layer:unsupported",`Unsupported Feature layer type ${e.layer.type}:${e.layer.source.type}`)}e([l({constructOnly:!0})],w.prototype,"layer",void 0),w=e([c("esri.views.3d.layers.support.featureTileQuery3D.FeatureTileClientQuery3D")],w);const g=1024;export{q as createFeatureTileQuery3D};
