import { join } from 'node:path';
export class InMemoryReviewFileGateway {
    files = new Map();
    async listReviews(projectPath) {
        const prefix = this.getReviewsDirectory(projectPath) + '/';
        const reviews = [];
        for (const [path, content] of this.files.entries()) {
            if (!path.startsWith(prefix))
                continue;
            const filename = path.slice(prefix.length);
            const match = filename.match(/^(\d{4}-\d{2}-\d{2})-(?:MR|PR)-([^-]+)-(.+)\.md$/);
            if (match) {
                const title = this.extractTitle(content);
                reviews.push({
                    filename,
                    path,
                    date: match[1],
                    mrNumber: match[2],
                    type: match[3],
                    size: content.length,
                    mtime: new Date().toISOString(),
                    title,
                });
            }
        }
        return reviews.sort((a, b) => b.mtime.localeCompare(a.mtime));
    }
    async readReview(projectPath, filename) {
        const path = join(this.getReviewsDirectory(projectPath), filename);
        return this.files.get(path) ?? null;
    }
    async deleteReview(projectPath, filename) {
        const path = join(this.getReviewsDirectory(projectPath), filename);
        return this.files.delete(path);
    }
    async reviewExists(projectPath, filename) {
        const path = join(this.getReviewsDirectory(projectPath), filename);
        return this.files.has(path);
    }
    getReviewsDirectory(projectPath) {
        return join(projectPath, '.claude', 'reviews');
    }
    addReview(projectPath, filename, content) {
        const path = join(this.getReviewsDirectory(projectPath), filename);
        this.files.set(path, content);
    }
    clear() {
        this.files.clear();
    }
    extractTitle(content) {
        const firstLine = content.split('\n')[0];
        const match = firstLine.match(/^# Code Review - (?:MR|PR) [#!]\d+ \((.+)\)$/);
        return match?.[1];
    }
}
//# sourceMappingURL=reviewFile.stub.js.map