// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/lang dojo/_base/array esri/tasks/query esri/tasks/QueryTask ./FeatureLayerQueryResult".split(" "),function(m,k,n,p,u,q){return m(null,{queryUrl:"",idProperty:"id",data:null,_entityData:null,constructor:function(a){m.safeMixin(this,a);this.data=[];this._entityData=[];this.layer=a.layer;this.objectIds=a.objectIds;this.where=a.where;this.orderByFields=a.orderByFields;this.totalCount=a.totalCount;this.batchCount=a.batchCount||25;this.idProperty=this.layer.objectIdField;
this.spatialFilter=a.spatialFilter;this.layer&&this.layer.url&&(this.queryTask=new u(this.layer.url))},get:function(a){return this.data[a]},getIdentity:function(a){return a[this.idProperty]},query:function(a,g){var d=new p,f=g&&g.start||0,l=g._export_count||this.batchCount,e=null;"function"===typeof a?e=a(this._entityData):"[object Array]"===Object.prototype.toString.call(a)&&(e=a);this.objectIds?(e=e?e:this.objectIds,d.objectIds=e.length>=f+this.batchCount?e.slice(f,f+l):e.slice(f)):(e&&0<e.length?
d.objectIds=e.length>=f+this.batchCount?e.slice(f,f+l):e.slice(f):(d.start=f,d.num=l,d.where=this.where,d.geometry=this.spatialFilter,d.spatialRelationship=p.SPATIAL_REL_INTERSECTS),(a=g.sort)&&0<a.length&&(a=n.map(a,function(b){return b.attribute+" "+(b.descending?"DESC":"ASC")}),d.orderByFields=a));d.returnGeometry="esriGeometryPoint"===this.layer.geometryType;d.outFields=["*"];var v=this.totalCount;a=null;a=!d.where;if(!(d.objectIds&&0<d.objectIds.length)&&a)return new q([]);a=this.queryTask?this.queryTask.execute(d):
this.layer.queryFeatures(d);a.total=a.then(k.hitch(this,function(b){var c=0,h=this.layer.objectIdField;if(this.objectIds){if(!h)for(c=0;c<b.fields.length;c++)if("esriFieldTypeOID"===b.fields[c].type){h=b.fields[c].name;break}var r={};for(c=0;c<b.features.length;c++)r[b.features[c].attributes[h]]=b.features[c];b.features=n.map(d.objectIds,function(w){return r[w]})}for(c=0;c<b.features.length;c++)if(b.features[c]){var t=b.features[c];b.features[c]=k.mixin(k.clone(t.attributes),{geometry:t.geometry});
this.data[b.features[c][h]]=b.features[c];this._entityData.push(b.features[c])}b=b.features;return v}),function(){console.log("FeatureLayerQueryStore queryFeatures failed.");return 0});return new q(a)}})});