/*
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","../../../../chunks/tslib.es6","../../../../core/Accessor","../../../../core/Error","../../../../core/Handles","../../../../core/maybe","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/Extent","../../../../layers/graphics/data/QueryEngine","../../../../rest/support/FeatureSet","../../../../rest/support/Query"],(function(e,r,t,n,o,s,u,i,a,y,c,l,p,d,h,f){"use strict";const Q=d.QueryEngine;e.I3SQueryEngine=function(e){function t(r){var t;return(t=e.call(this,r)||this)._dataQueryEngineInstance=null,t._handles=new s,t}r._inheritsLoose(t,e);var n=t.prototype;return n.initialize=function(){this._handles.add(this.layerView.on("visible-geometry-changed",(()=>this.spatialIndex.events.emit("changed"))))},n.destroy=function(){this._dataQueryEngineInstance&&(this._dataQueryEngineInstance.destroy(),this._dataQueryEngineInstance=null),this._handles&&(this._handles.destroy(),this._handles=null),this._set("layerView",null)},n.executeQueryForCount=function(){var e=r._asyncToGenerator((function*(e,r){return this.dataQueryEngine.executeQueryForCount(this._ensureQueryJSON(e),r)}));function t(r,t){return e.apply(this,arguments)}return t}(),n.executeQueryForExtent=function(){var e=r._asyncToGenerator((function*(e,r){const{count:t,extent:n}=yield this.dataQueryEngine.executeQueryForExtent(this._ensureQueryJSON(e),r);return{count:t,extent:p.fromJSON(n)}}));function t(r,t){return e.apply(this,arguments)}return t}(),n.executeQueryForIds=function(){var e=r._asyncToGenerator((function*(e,r){return this.dataQueryEngine.executeQueryForIds(this._ensureQueryJSON(e),r)}));function t(r,t){return e.apply(this,arguments)}return t}(),n.executeQuery=function(){var e=r._asyncToGenerator((function*(e,r){const t=this._ensureQueryJSON(e);if(t.returnGeometry)throw new o("feature-store:unsupported-query","returnGeometry is not yet supported for mesh scene layer queries");if(t.returnCentroid)throw new o("feature-store:unsupported-query","returnCentroid is not yet supported for mesh scene layer queries");const n=yield this.dataQueryEngine.executeQuery(t,r),s=h.fromJSON(n);return s.features.forEach((e=>{e.geometry=null})),s}));function t(r,t){return e.apply(this,arguments)}return t}(),n._ensureQueryJSON=function(e){return u.isNone(e)?this.defaultQueryJSON:e.toJSON()},n._ensureDataQueryEngine=function(){if(this._dataQueryEngineInstance)return this._dataQueryEngineInstance;const e=this.layer.objectIdField||"OBJECTID",r="esriGeometryPolygon",t=this.layer.fields.map((e=>e.toJSON())),n=this.layerView.view.resourceController.scheduler,o=this.spatialReference.toJSON(),s=this.priority,u=this.spatialIndex;return this._dataQueryEngineInstance=new Q({hasZ:!0,hasM:!1,geometryType:r,fields:t,timeInfo:null,spatialReference:o,objectIdField:e,featureStore:u,scheduler:n,priority:s}),this._dataQueryEngineInstance},r._createClass(t,[{key:"defaultQueryJSON",get:function(){return new f({outSpatialReference:this.spatialReference}).toJSON()}},{key:"dataQueryEngine",get:function(){return this._ensureDataQueryEngine()}}]),t}(n),t.__decorate([i.property({constructOnly:!0})],e.I3SQueryEngine.prototype,"layerView",void 0),t.__decorate([i.property({constructOnly:!0})],e.I3SQueryEngine.prototype,"priority",void 0),t.__decorate([i.property({constructOnly:!0})],e.I3SQueryEngine.prototype,"spatialIndex",void 0),t.__decorate([i.property({readOnly:!0,aliasOf:"layerView.view.spatialReference"})],e.I3SQueryEngine.prototype,"spatialReference",void 0),t.__decorate([i.property({readOnly:!0,aliasOf:"layerView.i3slayer"})],e.I3SQueryEngine.prototype,"layer",void 0),t.__decorate([i.property({readOnly:!0})],e.I3SQueryEngine.prototype,"defaultQueryJSON",null),e.I3SQueryEngine=t.__decorate([l.subclass("esri.views.3d.layers.i3s.I3SQueryEngine")],e.I3SQueryEngine),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
