/**
 * Progress Tracker
 *
 * Tracks task execution progress with ETA estimation and checkpoints.
 */
import { EventEmitter } from 'events';
export class ProgressTracker extends EventEmitter {
    total = 0;
    completed = 0;
    failed = 0;
    startTime = 0;
    taskTimes = new Map();
    start(total) {
        this.total = total;
        this.completed = 0;
        this.failed = 0;
        this.startTime = Date.now();
        this.emit('start', { total });
    }
    update(taskId, status, message) {
        if (status === 'completed') {
            this.completed++;
            this.taskTimes.set(taskId, Date.now());
        }
        else if (status === 'failed') {
            this.failed++;
        }
        const update = {
            taskId,
            status,
            total: this.total,
            completed: this.completed,
            failed: this.failed,
            eta: this.estimateETA(),
            message,
        };
        this.emit('progress', update);
    }
    estimateETA() {
        if (this.completed === 0)
            return undefined;
        const elapsed = Date.now() - this.startTime;
        const avgTime = elapsed / this.completed;
        const remaining = this.total - this.completed - this.failed;
        return Math.round(avgTime * remaining);
    }
    getProgress() {
        const done = this.completed + this.failed;
        return {
            percentage: this.total > 0 ? Math.round((done / this.total) * 100) : 0,
            completed: this.completed,
            total: this.total,
            eta: this.estimateETA(),
        };
    }
    reset() {
        this.total = 0;
        this.completed = 0;
        this.failed = 0;
        this.startTime = 0;
        this.taskTimes.clear();
    }
}
//# sourceMappingURL=progress-tracker.js.map