var QueryTask_1;import{__decorate}from"tslib";import Query from"@arcgis/core/tasks/support/Query";import StatisticDefinition from"@arcgis/core/tasks/support/StatisticDefinition";import{LayerDataSource}from"./__Empty.js";import{LayerMapSource}from"./__Empty.js";import{validation}from"../../Validation.js";import{isArcGisApiVersion3x}from"./ArcGisApiVersion.js";import{inline,isAbortable,schedulePromiseCancellation}from"./tools.js";import{MapProvider}from"./MapProvider.js";import{activate}from"../../Hooks.js";import EsriQueryTask from"@arcgis/core/tasks/QueryTask";let QueryTask=QueryTask_1=class{static getToJSONFunctionName(){return isArcGisApiVersion3x?"toJson":"toJSON"}static isToJSONMissing(t){return"object"==typeof t&&"function"!=typeof t[QueryTask_1.getToJSONFunctionName()]}static isLayerMapSource(t){return"mapLayer"===t.type}static addToJSON(i){if(isArcGisApiVersion3x){let t;return t=new(QueryTask_1.isLayerMapSource(i)?LayerMapSource:LayerDataSource)(i),t}{let t;const e=QueryTask_1.getToJSONFunctionName();t=QueryTask_1.isLayerMapSource(i)?function(){return{type:this.type,mapLayerId:this.mapLayerId,gdbVersion:this.gdbVersion}}:function(){return{type:this.type,dataSource:this.dataSource&&"function"==typeof this.dataSource[e]?this.dataSource[e]():this.dataSource}},i[e]=t}return i}execute(t,i,e){var a=validation.urlOrLayer(t,isArcGisApiVersion3x),r=validation.string("gdbVersion",t.gdbVersion,void 0);let s=validation.exists("source",t.source,void 0);const o=new Query;QueryTask_1.isToJSONMissing(s)&&(s=QueryTask_1.addToJSON(s)),o.distance=validation.number("distance",t.distance,void 0),o.geometry=validation.exists("geometry",t.geometry,void 0),o.geometryPrecision=validation.exists("geometryPrecision",t.geometryPrecision,void 0),o.groupByFieldsForStatistics=validation.array("groupByFieldsForStatistics",t.groupByFieldsForStatistics,void 0),o.maxAllowableOffset=validation.number("maxAllowableOffset",t.maxAllowableOffset,void 0),o.multipatchOption=validation.string("multipatchOption",t.multipatchOption,void 0),o.start=validation.number("start",t.start,void 0),o.num=validation.number("count",t.count,void 0),o.objectIds=validation.array("ids",t.ids,void 0),o.orderByFields=validation.array("orderByFields",t.orderByFields,void 0),o.outFields=validation.array("outFields",t.outFields,void 0);var n=validation.array("outStatistics",t.outStatistics,void 0);if(n){o.outStatistics=[];for(const c of n){const d=new StatisticDefinition;d.onStatisticField=c.onStatisticField,d.outStatisticFieldName=c.outStatisticFieldName,d.statisticType=c.statisticType,o.outStatistics.push(d)}}o.pixelSize=validation.exists("pixelSize",t.pixelSize,void 0),o.quantizationParameters=validation.exists("quantizationParameters",t.quantizationParameters,void 0),o.returnGeometry=validation.boolean("returnGeometry",t.returnGeometry,!1),o.returnDistinctValues=validation.boolean("returnDistinctValues",t.returnDistinctValues,!1),o.text=validation.string("text",t.text,void 0),o.where=validation.string("where",t.where,void 0);const l=validation.string("spatialRelationship",t.spatialRelationship,void 0);void 0!==l&&(l.match(/^[TF012\*]{9}$/)?(o.spatialRelationship="esriSpatialRelRelation",o.relationParam=l):o.spatialRelationship=this.getEsriSpatialRelationship(l));t=validation.exists("outSpatialReference",t.outSpatialReference,void 0);o.outSpatialReference=e.getOutSR(t);const u=new EsriQueryTask(a,{gdbVersion:r,source:s});r=isAbortable(i.cancellationToken)?{signal:i.cancellationToken.signal}:void 0,r=u.execute(o,r);return schedulePromiseCancellation(i,r),inline(r,function(t){return{feature:t.features[0],features:t.features,results:t}})}getEsriSpatialRelationship(t){switch(t){case"contains":return"esriSpatialRelContains";case"crosses":return"esriSpatialRelCrosses";case"intersects":return"esriSpatialRelIntersects";case"envelope-intersects":return"esriSpatialRelEnvelopeIntersects";case"index-intersects":return"esriSpatialRelIndexIntersects";case"overlaps":return"esriSpatialRelOverlaps";case"touches":return"esriSpatialRelTouches";case"within":return"esriSpatialRelWithin";default:return t}}};QueryTask.action="gcx:wf:arcgis:query:QueryTask",QueryTask.suite="gcx:wf:builtin",QueryTask=QueryTask_1=__decorate([activate(MapProvider)],QueryTask);export{QueryTask};