"use strict";
/**
 * Duration tracking plugin (per-phase and total).
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DurationTrackerPlugin = void 0;
class DurationTrackerPlugin {
    name = 'duration';
    phaseStartTime = Date.now();
    phaseSnapshots = [];
    onPhaseTransition(fromPhase, _toPhase, _ctx, store) {
        const now = Date.now();
        this.phaseSnapshots.push({
            phase: fromPhase,
            startTime: this.phaseStartTime,
            endTime: now,
            durationMs: now - this.phaseStartTime,
        });
        this.phaseStartTime = now;
        store.set('duration', {
            phaseSnapshots: [...this.phaseSnapshots],
            totalDurationMs: 0,
        });
    }
    onFinalize(_resultMessage, totalDurationMs, ctx, store) {
        const now = Date.now();
        this.phaseSnapshots.push({
            phase: ctx.currentPhase,
            startTime: this.phaseStartTime,
            endTime: now,
            durationMs: now - this.phaseStartTime,
        });
        store.set('duration', {
            phaseSnapshots: [...this.phaseSnapshots],
            totalDurationMs,
        });
    }
}
exports.DurationTrackerPlugin = DurationTrackerPlugin;
