"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PRReviewAssistant = void 0;
class PRReviewAssistant {
    generateSummary(title, diff, patterns) {
        const lines = diff.split('\n');
        const added = lines.filter((l) => l.startsWith('+') && !l.startsWith('+++')).length;
        const removed = lines.filter((l) => l.startsWith('-') && !l.startsWith('---')).length;
        const files = new Set();
        for (const line of lines) {
            const match = line.match(/^\+\+\+\s+b\/(.+)/);
            if (match)
                files.add(match[1]);
        }
        const potentialBugs = this.detectPotentialBugs(diff);
        const patternDeviations = this.detectPatternDeviations(diff, patterns);
        return {
            title,
            filesChanged: files.size,
            linesAdded: added,
            linesRemoved: removed,
            patternsDetected: patterns.filter(p => p.confidence.mean >= 0.5),
            potentialBugs,
            patternDeviations,
        };
    }
    detectPotentialBugs(diff) {
        const bugs = [];
        const lines = diff.split('\n');
        for (const line of lines) {
            if (!line.startsWith('+') || line.startsWith('+++'))
                continue;
            const code = line.substring(1);
            if (/console\.(log|warn|error)/.test(code)) {
                bugs.push(`Debug statement left in: ${code.trim()}`);
            }
            if (/\.only\(/.test(code)) {
                bugs.push(`Test isolation issue: .only() found: ${code.trim()}`);
            }
            if (/TODO|FIXME|HACK/.test(code)) {
                bugs.push(`Unresolved TODO/FIXME: ${code.trim()}`);
            }
            if (/setTimeout\(.*,\s*0\)/.test(code)) {
                bugs.push(`Potential race condition: setTimeout with 0ms: ${code.trim()}`);
            }
        }
        return bugs;
    }
    detectPatternDeviations(diff, patterns) {
        const deviations = [];
        const lines = diff.split('\n');
        for (const line of lines) {
            if (!line.startsWith('+') || line.startsWith('+++'))
                continue;
            const code = line.substring(1);
            for (const pattern of patterns) {
                if (pattern.confidence.mean >= 0.7) {
                    if (pattern.category === 'variable_declaration' && /\bvar\s+/.test(code)) {
                        deviations.push(`Pattern deviation: uses 'var' but team prefers '${pattern.to}' (${pattern.confidence.mean})`);
                    }
                    if (pattern.category === 'function_style' && /\bfunction\b/.test(code)) {
                        deviations.push(`Pattern deviation: uses 'function' but team prefers '${pattern.to}' (${pattern.confidence.mean})`);
                    }
                    if (pattern.category === 'equality' && /(?<!=)=(?!=)/.test(code)) {
                        deviations.push(`Pattern deviation: uses '==' but team prefers '${pattern.to}' (${pattern.confidence.mean})`);
                    }
                }
            }
        }
        return deviations;
    }
    getReviewChecklist() {
        return [
            'Code follows team patterns and conventions',
            'Tests cover new functionality',
            'No debug statements or .only() in tests',
            'Error handling is present for async operations',
            'No hardcoded secrets or credentials',
            'Performance implications considered',
            'Documentation updated if needed',
        ];
    }
}
exports.PRReviewAssistant = PRReviewAssistant;
//# sourceMappingURL=pr-review-assistant.js.map