/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../request.js";import{strict as s}from"../../core/jsonMap.js";import{createAbortError as r}from"../../core/promiseUtils.js";import{property as o,subclass as i}from"../../core/accessorSupport/decorators.js";import a from"../../rest/networks/support/ValidateNetworkTopologyResult.js";import{enumeration as n}from"../../core/accessorSupport/decorators/enumeration.js";const l=s()({Pending:"job-waiting",InProgress:"job-executing",Completed:"job-succeeded"});let d=class extends a{constructor(t){super(t),this.statusUrl=null,this.status=null,this.submissionTime=null,this.lastUpdatedTime=null,this._timer=void 0}destroy(){clearInterval(this._timer)}async checkJobStatus(t){const s={...t,query:{f:"json"}},{data:r}=await e(this.statusUrl,s);return this.read(r),this.editsResolver&&this.editsResolver.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],exceededTransferLimit:!0,historicMoment:null}),this}async waitForJobCompletion(t={}){const{interval:e=1e3,statusCallback:s}=t;return new Promise((t,o)=>{this._clearTimer();const i=setInterval(()=>{this._timer||o(r()),this.checkJobStatus().then(e=>{const{status:r}=e;switch(this.status=r,r){case"job-succeeded":this._clearTimer(),t(this);break;case"job-waiting":case"job-executing":s&&s(this)}},t=>{this._clearTimer(),o(t)})},e);this._timer=i})}_clearTimer(){clearInterval(this._timer),this._timer=void 0}};t([o()],d.prototype,"editsResolver",void 0),t([o({type:String,json:{write:!0}})],d.prototype,"statusUrl",void 0),t([n(l)],d.prototype,"status",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,e)=>{e.submissionTime=t?t.getTime():null}}}})],d.prototype,"submissionTime",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,e)=>{e.lastUpdatedTime=t?t.getTime():null}}}})],d.prototype,"lastUpdatedTime",void 0),d=t([i("esri.networks.support.TopologyValidationJobInfo")],d);const c=d;export{c as default};
