define(["require","exports","tslib","./esriDelegate!esri/tasks/support/Query","./esriDelegate!esri/tasks/support/StatisticDefinition","./esriDelegate!esri/layers/LayerDataSource","./esriDelegate!esri/layers/LayerMapSource","../../Validation","./ArcGisApiVersion","./tools","./MapProvider","../../Hooks","esri/tasks/QueryTask"],function(e,t,i,p,v,a,r,y,S,f,s,o,g){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),g=i.__importDefault(g);var m,s=((m=n).getToJSONFunctionName=function(){return S.isArcGisApiVersion3x?"toJson":"toJSON"},n.isToJSONMissing=function(e){return"object"==typeof e&&"function"!=typeof e[m.getToJSONFunctionName()]},n.isLayerMapSource=function(e){return"mapLayer"===e.type},n.addToJSON=function(e){if(S.isArcGisApiVersion3x)return new(m.isLayerMapSource(e)?r.LayerMapSource:a.LayerDataSource)(e);var t=void 0,i=m.getToJSONFunctionName(),t=m.isLayerMapSource(e)?function(){return{type:this.type,mapLayerId:this.mapLayerId,gdbVersion:this.gdbVersion}}:function(){return{type:this.type,dataSource:this.dataSource&&"function"==typeof this.dataSource[i]?this.dataSource[i]():this.dataSource}};return e[i]=t,e},n.prototype.execute=function(e,t,i){var a=y.validation.urlOrLayer(e,S.isArcGisApiVersion3x),r=y.validation.string("gdbVersion",e.gdbVersion,void 0),s=y.validation.exists("source",e.source,void 0),o=new p.Query;m.isToJSONMissing(s)&&(s=m.addToJSON(s)),o.distance=y.validation.number("distance",e.distance,void 0),o.geometry=y.validation.exists("geometry",e.geometry,void 0),o.geometryPrecision=y.validation.exists("geometryPrecision",e.geometryPrecision,void 0),o.groupByFieldsForStatistics=y.validation.array("groupByFieldsForStatistics",e.groupByFieldsForStatistics,void 0),o.maxAllowableOffset=y.validation.number("maxAllowableOffset",e.maxAllowableOffset,void 0),o.multipatchOption=y.validation.string("multipatchOption",e.multipatchOption,void 0),o.start=y.validation.number("start",e.start,void 0),o.num=y.validation.number("count",e.count,void 0),o.objectIds=y.validation.array("ids",e.ids,void 0),o.orderByFields=y.validation.array("orderByFields",e.orderByFields,void 0),o.outFields=y.validation.array("outFields",e.outFields,void 0);var n=y.validation.array("outStatistics",e.outStatistics,void 0);if(n){o.outStatistics=[];for(var l=0,u=n;l<u.length;l++){var c=u[l],d=new v.StatisticDefinition;d.onStatisticField=c.onStatisticField,d.outStatisticFieldName=c.outStatisticFieldName,d.statisticType=c.statisticType,o.outStatistics.push(d)}}o.pixelSize=y.validation.exists("pixelSize",e.pixelSize,void 0),o.quantizationParameters=y.validation.exists("quantizationParameters",e.quantizationParameters,void 0),o.returnGeometry=y.validation.boolean("returnGeometry",e.returnGeometry,!1),o.returnDistinctValues=y.validation.boolean("returnDistinctValues",e.returnDistinctValues,!1),o.text=y.validation.string("text",e.text,void 0),o.where=y.validation.string("where",e.where,void 0);n=y.validation.string("spatialRelationship",e.spatialRelationship,void 0);void 0!==n&&(n.match(/^[TF012\*]{9}$/)?(o.spatialRelationship="esriSpatialRelRelation",o.relationParam=n):o.spatialRelationship=this.getEsriSpatialRelationship(n));e=y.validation.exists("outSpatialReference",e.outSpatialReference,void 0);o.outSpatialReference=i.getOutSR(e);r=new g.default(a,{gdbVersion:r,source:s}),s=f.isAbortable(t.cancellationToken)?{signal:t.cancellationToken.signal}:void 0,s=r.execute(o,s);return f.schedulePromiseCancellation(t,s),f.inline(s,function(e){return{feature:e.features[0],features:e.features,results:e}})},n.prototype.getEsriSpatialRelationship=function(e){switch(e){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 e}},n.action="gcx:wf:arcgis:query:QueryTask",n.suite="gcx:wf:builtin",m=i.__decorate([o.activate(s.MapProvider)],n));function n(){}t.QueryTask=s});