"use strict";
/**
 * ParsedFile - Shared file representation for all detectors
 *
 * Provides lazy-cached line splitting and common context-extraction
 * operations, eliminating duplicated content.split('\n') calls across 26+ detectors.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParsedFile = void 0;
exports.severityRank = severityRank;
exports.confidenceRank = confidenceRank;
class ParsedFile {
    constructor(content, filePath) {
        this._lines = null;
        this.content = content;
        this.filePath = filePath;
    }
    /** Lazy-cached array of lines from content.split('\n') */
    get lines() {
        if (this._lines === null) {
            this._lines = this.content.split('\n');
        }
        return this._lines;
    }
    /** Number of lines in the file */
    get lineCount() {
        return this.lines.length;
    }
    /** Get a single line by 0-based index. Returns '' for out-of-bounds. */
    line(index) {
        if (index < 0 || index >= this.lines.length)
            return '';
        return this.lines[index];
    }
    /**
     * Get surrounding lines around a center index, clamped to file bounds.
     * @param lineIndex 0-based center line
     * @param windowSize number of lines before and after center
     */
    getSurroundingLines(lineIndex, windowSize) {
        const startIndex = Math.max(0, lineIndex - windowSize);
        const endIndex = Math.min(this.lines.length - 1, lineIndex + windowSize);
        const slice = this.lines.slice(startIndex, endIndex + 1);
        return {
            lines: slice,
            startIndex,
            endIndex,
            text: slice.join('\n'),
        };
    }
    /**
     * Get a range of lines as a joined string.
     * @param start 0-based start (inclusive), clamped to bounds
     * @param end 0-based end (inclusive), clamped to bounds
     */
    getLineRange(start, end) {
        const s = Math.max(0, start);
        const e = Math.min(this.lines.length - 1, end);
        if (s > e)
            return '';
        return this.lines.slice(s, e + 1).join('\n');
    }
    /** Construct from a ScanFile-like object with content and path */
    static from(file) {
        return new ParsedFile(file.content, file.path);
    }
}
exports.ParsedFile = ParsedFile;
/**
 * Numeric rank for severity comparisons.
 * Only relative ordering matters — used for keeping the higher-severity finding
 * during deduplication and merge operations.
 */
function severityRank(severity) {
    const ranks = {
        critical: 5,
        high: 4,
        medium: 3,
        low: 2,
        info: 1,
    };
    return ranks[severity] || 0;
}
/**
 * Numeric rank for confidence comparisons.
 */
function confidenceRank(confidence) {
    const ranks = {
        high: 3,
        medium: 2,
        low: 1,
    };
    return ranks[confidence] || 0;
}
//# sourceMappingURL=parsed-file.js.map