export class InMemoryReviewRequestTrackingGateway {
    storage = new Map();
    loadTracking(projectPath) {
        return this.storage.get(projectPath) ?? null;
    }
    saveTracking(projectPath, data) {
        this.storage.set(projectPath, data);
    }
    getById(projectPath, reviewRequestId) {
        const data = this.storage.get(projectPath);
        if (!data)
            return null;
        return data.mrs.find((mr) => mr.id === reviewRequestId) ?? null;
    }
    getByNumber(projectPath, reviewRequestNumber, platform) {
        const data = this.storage.get(projectPath);
        if (!data)
            return null;
        return data.mrs.find((mr) => mr.mrNumber === reviewRequestNumber && mr.platform === platform) ?? null;
    }
    create(projectPath, reviewRequest) {
        let data = this.storage.get(projectPath);
        if (!data) {
            data = {
                mrs: [],
                lastUpdated: new Date().toISOString(),
                stats: {
                    totalMrs: 0,
                    totalReviews: 0,
                    totalFollowups: 0,
                    averageReviewsPerMr: 0,
                    averageTimeToApproval: null,
                    topAssigners: [],
                },
            };
        }
        data.mrs.push(reviewRequest);
        data.stats.totalMrs = data.mrs.length;
        data.lastUpdated = new Date().toISOString();
        this.storage.set(projectPath, data);
    }
    update(projectPath, reviewRequestId, updates) {
        const data = this.storage.get(projectPath);
        if (!data)
            return;
        const index = data.mrs.findIndex((mr) => mr.id === reviewRequestId);
        if (index === -1)
            return;
        data.mrs[index] = { ...data.mrs[index], ...updates };
        data.lastUpdated = new Date().toISOString();
        this.storage.set(projectPath, data);
    }
    getByState(projectPath, state) {
        const data = this.storage.get(projectPath);
        if (!data)
            return [];
        return data.mrs.filter((mr) => mr.state === state);
    }
    getActiveMrs(projectPath) {
        const data = this.storage.get(projectPath);
        if (!data)
            return [];
        return data.mrs.filter((mr) => mr.state !== 'merged' && mr.state !== 'closed');
    }
    remove(projectPath, reviewRequestId) {
        const data = this.storage.get(projectPath);
        if (!data)
            return false;
        const index = data.mrs.findIndex((mr) => mr.id === reviewRequestId);
        if (index === -1)
            return false;
        data.mrs.splice(index, 1);
        data.stats.totalMrs = data.mrs.length;
        data.lastUpdated = new Date().toISOString();
        this.storage.set(projectPath, data);
        return true;
    }
    archive(projectPath, reviewRequestId) {
        return this.remove(projectPath, reviewRequestId);
    }
    recordReviewEvent(projectPath, reviewRequestId, event) {
        const data = this.storage.get(projectPath);
        if (!data)
            return;
        const mr = data.mrs.find((m) => m.id === reviewRequestId);
        if (!mr)
            return;
        mr.reviews.push(event);
        mr.lastReviewAt = event.timestamp;
        if (event.type === 'review') {
            mr.totalReviews++;
            data.stats.totalReviews++;
        }
        else {
            mr.totalFollowups++;
            data.stats.totalFollowups++;
        }
        mr.totalBlocking += event.blocking;
        mr.totalWarnings += event.warnings;
        mr.totalSuggestions += event.suggestions;
        mr.totalDurationMs += event.durationMs;
        data.lastUpdated = new Date().toISOString();
        this.storage.set(projectPath, data);
    }
    recordPush(projectPath, reviewRequestNumber, platform) {
        const data = this.storage.get(projectPath);
        if (!data)
            return null;
        const mr = data.mrs.find((m) => m.mrNumber === reviewRequestNumber && m.platform === platform);
        if (!mr)
            return null;
        mr.lastPushAt = new Date().toISOString();
        data.lastUpdated = new Date().toISOString();
        this.storage.set(projectPath, data);
        return mr;
    }
    clear() {
        this.storage.clear();
    }
}
//# sourceMappingURL=reviewRequestTracking.stub.js.map