/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{watch as s,sync as n}from"../../../../core/reactiveUtils.js";import{property as i,subclass as a}from"../../../../core/accessorSupport/decorators.js";import o from"../../../../geometry/Extent.js";import{fallbackObjectIDAttribute as u}from"../../../../layers/LayerConstants.js";import{QueryEngine as y}from"../../../../layers/graphics/data/QueryEngine.js";import l from"../../../../layers/support/FieldsIndex.js";import c from"../../../../rest/support/FeatureSet.js";import d from"../../../../rest/support/Query.js";const p=y;let h=class extends t{constructor(e){super(e)}initialize(){this.addHandles(this.layerView.on("visible-geometry-changed",()=>this.spatialIndex.events.emit("changed"))),this.addHandles(s(()=>this.layerView.availableFields,()=>this._dataQueryEngineInstance=r(this._dataQueryEngineInstance),n))}destroy(){this._dataQueryEngineInstance=r(this._dataQueryEngineInstance),this._set("layerView",null)}get spatialReference(){return this.layerView.view.spatialReference}get layer(){return this.layerView.layer}get defaultQueryJSON(){return new d({outSpatialReference:this.spatialReference}).toJSON()}get _dataQueryEngine(){return this._ensureDataQueryEngine()}async executeQueryForCount(e,t){return this._dataQueryEngine.executeQueryForCount(this._ensureQueryJSON(e),t)}async executeQueryForExtent(e,t){const{count:r,extent:s}=await this._dataQueryEngine.executeQueryForExtent(this._ensureQueryJSON(e),t);return{count:r,extent:o.fromJSON(s)}}async executeQueryForIds(e,t){return this._dataQueryEngine.executeQueryForIds(this._ensureQueryJSON(e),t)}async executeQuery(e,t){const r=this._ensureQueryJSON(e),s=await this._dataQueryEngine.executeQuery(r,t);if(e?.returnGeometry){const{processQueryGeometries:e}=await import("./I3SQueryResultGeometry.js");return e(this.layerView,s)}return c.fromJSON(s)}_ensureQueryJSON(e){return null==e?this.defaultQueryJSON:e.toJSON()}_ensureDataQueryEngine(){if(this._dataQueryEngineInstance)return this._dataQueryEngineInstance;const e=this.layer.objectIdField||u,t="esriGeometryPolygon",r=this.layer.fieldsIndex?.toJSON()||new l([]),s=this.layerView.view.resourceController.scheduler,n=this.spatialReference.toJSON(),i=this.priority,a=this.spatialIndex,o=this.layerView.availableFields??[];return this._dataQueryEngineInstance=new p({hasZ:!0,hasM:!1,geometryType:t,fieldsIndex:r,timeInfo:null,spatialReference:n,featureIdInfo:{type:"object-id",fieldName:e},featureStore:a,scheduler:s,priority:i,availableFields:o}),this._dataQueryEngineInstance}};e([i({constructOnly:!0})],h.prototype,"layerView",void 0),e([i({constructOnly:!0})],h.prototype,"priority",void 0),e([i({constructOnly:!0})],h.prototype,"spatialIndex",void 0),e([i()],h.prototype,"spatialReference",null),e([i()],h.prototype,"layer",null),e([i()],h.prototype,"defaultQueryJSON",null),h=e([a("esri.views.3d.layers.i3s.I3SQueryEngine")],h);export{h as I3SQueryEngine};
