/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../request","../core/accessorSupport/decorators/property","../core/arrayUtils","../core/has","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/subclass","../layers/graphics/sources/support/QueryTask","../layers/support/source/DataLayerSource","../renderers/support/jsonUtils","../rest/support/Query","../rest/support/StatisticDefinition","./Task"],(function(e,t,s,r,n,i,o,a,l,u,c,p,d,f){"use strict";let h=function(t){function r(e){var s;return(s=t.call(this,e)||this)._field=null,s.checkValueRange=null,s.gdbVersion=null,s.source=null,s}e._inheritsLoose(r,t);var n=r.prototype;return n.execute=function(e,t){const{classificationDefinition:r}=e,n={...e.toJSON(),f:"json"};if("esri.rest.support.ClassBreaksDefinition"===r.declaredClass?this._field=r.classificationField:this._field=r.attributeField,this.source){var i;const e={source:null==(i=this.source)?void 0:i.toJSON()};n.layer=JSON.stringify(e)}this.gdbVersion&&(n.gdbVersion=this.gdbVersion),n.classificationDef&&(n.classificationDef=JSON.stringify(n.classificationDef));let o={query:n};return(this.requestOptions||t)&&(o={...this.requestOptions,...t,...o}),s(this.parsedUrl.path,o).then((e=>this._handleExecuteResponse(e)))},n._handleExecuteResponse=function(e){const t=e&&e.data;if(!t)return;if(!this.checkValueRange){const e=this._processRendererJSON(t);return Promise.resolve(e)}const s=new l({url:this.url}),r=new d({statisticType:"min",onStatisticField:this._field}),n=new d({statisticType:"max",onStatisticField:this._field}),i=new p({outStatistics:[r,n]});return s.execute(i).then((e=>{const s=e.features[0].attributes;let r=null,n=null;for(const t in s)0===t.toLowerCase().indexOf("min")?r=s[t]:n=s[t];return this._processRendererJSON(t,r,n)}))},n._processRendererJSON=function(e,t,s){if("classBreaks"===e.type){const r=c.fromJSON(e);return{classBreaks:r.classBreakInfos.map(((e,n)=>(0===n&&null!=t&&(e.minValue=t),n===r.classBreakInfos.length-1&&null!=s&&(e.maxValue=s),{minValue:e.minValue,maxValue:e.maxValue,label:e.label}))),normalizationTotal:r.normalizationTotal}}return{uniqueValues:e.uniqueValueInfos.map(((r,n)=>(0===n&&null!=t&&(r.value=t),n===e.uniqueValueInfos.length-1&&null!=s&&(r.value=s),{count:r.count,value:r.value,label:r.label})))}},e._createClass(r,[{key:"parsedUrl",get:function(){const e=this._parseUrl(this.url);return e.path+="/generateRenderer",e}}]),r}(f);t.__decorate([r.property()],h.prototype,"checkValueRange",void 0),t.__decorate([r.property()],h.prototype,"gdbVersion",void 0),t.__decorate([r.property({type:u.DataLayerSource})],h.prototype,"source",void 0),t.__decorate([r.property({readOnly:!0})],h.prototype,"parsedUrl",null),h=t.__decorate([a.subclass("esri.tasks.GenerateRendererTask")],h);return h}));
