/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
class e{constructor(){this._commands=new Map,this._historicMoment=null}tryAdd(e){if(!this._canDebounce(e))return!1;switch(e.type){case"override":return this._addOverride(e),!0;case"override-by-id":return this._addOverrideById(e),!0}}toMessage(){const e={historicMoment:this._historicMoment,commands:{updateByIdWeak:[],updateWeak:[],removeWeak:[],update:[],remove:[],release:[]}};for(const[s,o]of this._commands.entries())switch(o.type){case"override-update-by-id":e.commands.updateByIdWeak.push(s);break;case"override-update":o.isWeak?e.commands.updateWeak.push(o.feature):e.commands.update.push(o.feature);break;case"override-remove":o.isWeak?e.commands.removeWeak.push(s):e.commands.remove.push(s);break;case"override-release":e.commands.release.push(s)}return e}_canDebounce(e){switch(e.type){case"override":{const{updates:s,removed:o,release:t}=e;return!s.some(e=>this._commands.has(e.objectId))&&!o.some(e=>this._commands.has(e))&&!t.some(e=>this._commands.has(e))}case"override-by-id":{const{updates:s,removed:o}=e;return!s.some(e=>this._commands.has(e))&&!o.some(e=>this._commands.has(e))}}}_addOverrideById(e){this._historicMoment=e.historicMoment;for(const s of e.updates)this._commands.set(s,{type:"override-update-by-id",isWeak:e.isWeak});for(const s of e.removed)this._commands.set(s,{type:"override-remove",isWeak:e.isWeak})}_addOverride(e){this._historicMoment=e.historicMoment;for(const s of e.updates)this._commands.set(s.objectId,{type:"override-update",feature:s,isWeak:e.isWeak});for(const s of e.removed)this._commands.set(s,{type:"override-remove",isWeak:e.isWeak});for(const s of e.release)this._commands.set(s,{type:"override-release"})}}export{e as DebouncedFeatureOverride};
