import { calculateOverallProgress } from "../../entities/progress/progress.calculator.js";
export class ReviewProgressMemoryGateway {
    progressStore = new Map();
    onProgressChange = null;
    setOnProgressChange(callback) {
        this.onProgressChange = callback;
    }
    createProgress(jobId, agentNames) {
        const progress = {
            agents: agentNames.map((name) => ({
                name,
                displayName: name,
                status: "pending",
            })),
            currentPhase: "initializing",
            overallProgress: 0,
            lastUpdate: new Date(),
        };
        this.progressStore.set(jobId, progress);
        return progress;
    }
    getProgress(jobId) {
        return this.progressStore.get(jobId);
    }
    startAgent(jobId, agentName) {
        const progress = this.progressStore.get(jobId);
        if (!progress)
            return null;
        const agent = progress.agents.find((a) => a.name === agentName);
        if (!agent)
            return null;
        agent.status = "running";
        agent.startedAt = new Date();
        progress.lastUpdate = new Date();
        progress.overallProgress = calculateOverallProgress(progress);
        if (this.onProgressChange) {
            this.onProgressChange(jobId, progress);
        }
        return progress;
    }
    completeAgent(jobId, agentName, status, error) {
        const progress = this.progressStore.get(jobId);
        if (!progress)
            return null;
        const agent = progress.agents.find((a) => a.name === agentName);
        if (!agent)
            return null;
        agent.status = status === "success" ? "completed" : "failed";
        agent.completedAt = new Date();
        if (error) {
            agent.error = error;
        }
        progress.lastUpdate = new Date();
        progress.overallProgress = calculateOverallProgress(progress);
        if (this.onProgressChange) {
            this.onProgressChange(jobId, progress);
        }
        return progress;
    }
    setPhase(jobId, phase) {
        const progress = this.progressStore.get(jobId);
        if (!progress)
            return null;
        progress.currentPhase = phase;
        progress.lastUpdate = new Date();
        progress.overallProgress = calculateOverallProgress(progress);
        if (this.onProgressChange) {
            this.onProgressChange(jobId, progress);
        }
        return progress;
    }
}
//# sourceMappingURL=reviewProgress.memory.gateway.js.map