/* 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 r}from"../../core/promiseUtils.js";import{property as o,subclass as i}from"../../core/accessorSupport/decorators.js";import a from"../../rest/networks/support/TraceResult.js";import{enumeration as c}from"../../core/accessorSupport/decorators/enumeration.js";const n=s()({Pending:"job-waiting",InProgress:"job-executing",Completed:"job-succeeded"});let m=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),o=r.traceResults?{...r.traceResults,...r}:r;return this.read({...o,telecomSourceSet:this.telecomSourceSet}),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({type:String,json:{write:!0}})],m.prototype,"statusUrl",void 0),t([c(n)],m.prototype,"status",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,e)=>{e.submissionTime=t?t.getTime():null}}}})],m.prototype,"submissionTime",void 0),t([o({type:Date,json:{type:Number,write:{writer:(t,e)=>{e.lastUpdatedTime=t?t.getTime():null}}}})],m.prototype,"lastUpdatedTime",void 0),t([o({json:{read:!1}})],m.prototype,"telecomSourceSet",void 0),m=t([i("esri.networks.support.TraceJobInfo")],m);export{m as default};
