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