!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&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"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var p,i=e("tslib"),v=e("./esriDelegate!esri/tasks/support/Query"),y=e("./esriDelegate!esri/tasks/support/StatisticDefinition"),a=e("./esriDelegate!esri/layers/LayerDataSource"),r=e("./esriDelegate!esri/layers/LayerMapSource"),S=e("../../Validation"),f=e("./ArcGisApiVersion"),g=e("./tools"),s=e("./MapProvider"),o=e("../../Hooks"),m=i.__importDefault(e("esri/tasks/QueryTask")),s=((p=n).getToJSONFunctionName=function(){return f.isArcGisApiVersion3x?"toJson":"toJSON"},n.isToJSONMissing=function(e){return"object"==typeof e&&"function"!=typeof e[p.getToJSONFunctionName()]},n.isLayerMapSource=function(e){return"mapLayer"===e.type},n.addToJSON=function(e){if(f.isArcGisApiVersion3x)return new(p.isLayerMapSource(e)?r.LayerMapSource:a.LayerDataSource)(e);var t=void 0,i=p.getToJSONFunctionName(),t=p.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=S.validation.urlOrLayer(e,f.isArcGisApiVersion3x),r=S.validation.string("gdbVersion",e.gdbVersion,void 0),s=S.validation.exists("source",e.source,void 0),o=new v.Query;p.isToJSONMissing(s)&&(s=p.addToJSON(s)),o.distance=S.validation.number("distance",e.distance,void 0),o.geometry=S.validation.exists("geometry",e.geometry,void 0),o.geometryPrecision=S.validation.exists("geometryPrecision",e.geometryPrecision,void 0),o.groupByFieldsForStatistics=S.validation.array("groupByFieldsForStatistics",e.groupByFieldsForStatistics,void 0),o.maxAllowableOffset=S.validation.number("maxAllowableOffset",e.maxAllowableOffset,void 0),o.multipatchOption=S.validation.string("multipatchOption",e.multipatchOption,void 0),o.start=S.validation.number("start",e.start,void 0),o.num=S.validation.number("count",e.count,void 0),o.objectIds=S.validation.array("ids",e.ids,void 0),o.orderByFields=S.validation.array("orderByFields",e.orderByFields,void 0),o.outFields=S.validation.array("outFields",e.outFields,void 0);var n=S.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 y.StatisticDefinition;d.onStatisticField=c.onStatisticField,d.outStatisticFieldName=c.outStatisticFieldName,d.statisticType=c.statisticType,o.outStatistics.push(d)}}o.pixelSize=S.validation.exists("pixelSize",e.pixelSize,void 0),o.quantizationParameters=S.validation.exists("quantizationParameters",e.quantizationParameters,void 0),o.returnGeometry=S.validation.boolean("returnGeometry",e.returnGeometry,!1),o.returnDistinctValues=S.validation.boolean("returnDistinctValues",e.returnDistinctValues,!1),o.text=S.validation.string("text",e.text,void 0),o.where=S.validation.string("where",e.where,void 0);n=S.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=S.validation.exists("outSpatialReference",e.outSpatialReference,void 0);o.outSpatialReference=i.getOutSR(e);r=new m.default(a,{gdbVersion:r,source:s}),s=g.isAbortable(t.cancellationToken)?{signal:t.cancellationToken.signal}:void 0,s=r.execute(o,s);return g.schedulePromiseCancellation(t,s),g.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",p=i.__decorate([o.activate(s.MapProvider)],n));function n(){}t.QueryTask=s});