/*
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","../../../core/Error","../../../core/maybe","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../rest/support/FeatureSet","./FeatureLayerView2D","./support/util"],(function(e,t,r,n,o,i,a,s,c,l,p,u,y){"use strict";function d(e,t){if(n.isNone(e)&&n.isNone(t))return null;const r={};return n.isSome(t)&&(r.geometry=t.toJSON()),n.isSome(e)&&(r.where=e),r}let h=function(t){function n(){var e;return(e=t.apply(this,arguments)||this)._enabledDataReceived=!1,e.errorString=null,e.connectionStatus="disconnected",e}e._inheritsLoose(n,t);var i=n.prototype;return i.initialize=function(){this.handles.add([o.watch((()=>{var e;return null==(e=this.layer)?void 0:e.purgeOptions}),(()=>this._update())),o.watch((()=>this.suspended),(e=>{e?this._proxy.pauseStream():this._proxy.resumeStream()}))])},i.on=function(e,r){"data-received"===e&&(this._enabledDataReceived=!0,this._proxy.enableEvent("data-received",!0));const n=t.prototype.on.call(this,e,r),o=this;return{remove(){n.remove(),"data-received"===e&&(o._proxy.closed||o.hasEventListener("data-received")||o._proxy.enableEvent("data-received",!1))}}},i.queryLatestObservations=function(e,t){if(!(this.layer.timeInfo.endField||this.layer.timeInfo.startField))throw new r("streamlayer-no-timeField","queryLatestObservation can only be used with services that define a TrackIdField");return this._proxy.queryLatestObservations(this._cleanUpQuery(e),t).then((e=>{const t=p.fromJSON(e);return t.features.forEach((e=>{e.layer=this.layer,e.sourceLayer=this.layer})),t}))},i.detach=function(){t.prototype.detach.call(this),this.connectionStatus="disconnected"},i._createClientOptions=function(){return{...t.prototype._createClientOptions.call(this),setProperty:e=>{this.set(e.propertyName,e.value)}}},i._createTileRendererHash=function(e){const r=`${JSON.stringify(this.layer.purgeOptions)}.${JSON.stringify(d(this.layer.definitionExpression,this.layer.geometryDefinition))})`;return t.prototype._createTileRendererHash.call(this,e)+r},i._createServiceOptions=function(){var t=e._asyncToGenerator((function*(){const e=this.layer,{objectIdField:t}=e,r=e.fields.map((e=>e.toJSON())),n=y.toJSONGeometryType(e.geometryType),o=e.timeInfo&&e.timeInfo.toJSON()||null,i=e.spatialReference?e.spatialReference.toJSON():null;return{type:"stream",fields:r,geometryType:n,objectIdField:t,timeInfo:o,source:this.layer.parsedUrl,serviceFilter:d(this.layer.definitionExpression,this.layer.geometryDefinition),purgeOptions:this.layer.purgeOptions.toJSON(),enableDataReceived:this._enabledDataReceived,spatialReference:i,maxReconnectionAttempts:this.layer.maxReconnectionAttempts,maxReconnectionInterval:this.layer.maxReconnectionInterval,updateInterval:this.layer.updateInterval,customParameters:e.customParameters}}));function r(){return t.apply(this,arguments)}return r}(),e._createClass(n,[{key:"connectionError",get:function(){if(this.errorString)return new r("stream-controller",this.errorString)}}]),n}(u);t.__decorate([i.property()],h.prototype,"errorString",void 0),t.__decorate([i.property({readOnly:!0})],h.prototype,"connectionError",null),t.__decorate([i.property()],h.prototype,"connectionStatus",void 0),h=t.__decorate([l.subclass("esri.views.2d.layers.StreamLayerView2D")],h);return h}));
