import{mergeObject}from"../../common/utils/helpers.mjs";export default class ProgressEmitter{constructor(t,o,e,s={},i={}){this.#t=t,this.#o=o,this.#e=e,this.#s=s,this.#i=mergeObject({log:!0,decimalPlaces:0},i)}#t;#o=null;#e;#s;#i;#n;get operationString(){return this.#i.operationName?`${this.#i.operationName} | `:""}complete({event:t="progress",context:o={},log:e,step:s}={}){const{express:i,logger:n}=global,{log:r,onProgress:c}=this.#i,{STEPS:a}=CONST.SETUP_PACKAGE_PROGRESS;s??=a.COMPLETE;const g={...this.#s,...o,step:s,pct:100,action:this.#t};c instanceof Function&&c(g),r&&n.info(`${this.operationString}${e??`${s} - 100%`}`),i.io.emit(t,g)}emit(t,{event:o="progress",force:e=!1,log:s,context:i={}}={}){const{express:n,logger:r}=global,{log:c,decimalPlaces:a,onProgress:g}=this.#i,p=Math.min(Number((t/this.#e*100).toFixed(a)),100),l=p!==this.#n,h={...this.#s,...i,pct:p,hasChanged:l,action:this.#t,step:this.#o};if(g instanceof Function&&g(h),e||l){if(c){const t=s??`${this.#t} ${this.#o} progress`;r.info(`${this.operationString}${t} - ${p}%`)}n.io.emit(o,h),this.#n=p}}error(t,{event:o="progress",log:e,context:s={}}={}){const{express:i,logger:n}=global,{log:r,onProgress:c}=this.#i,{STEPS:a}=CONST.SETUP_PACKAGE_PROGRESS,g={...this.#s,...s,pct:100,action:this.#t,step:a.ERROR,error:t.message,stack:t.stack};c instanceof Function&&c(g),r&&n.error(e??t),i.io.emit(o,g)}nextStep(t,o,e={}){this.#o=t,this.#e=o,mergeObject(this.#s,e)}log(t){logger.info(`${this.operationString}${t}`)}}