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