"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileDiagnosticManager = void 0;
class FileDiagnosticManager {
    constructor() {
        this.diagnostics = [];
        this.initialized = false;
    }
    /**
     * Only used when initializing the manager
     */
    initWith(diagnostics) {
        if (this.initialized) {
            throw new Error('FileDiagnosticManager is already initialized');
        }
        diagnostics.forEach((d) => {
            this.diagnostics.push(d);
        });
        this.initialized = true;
    }
    getDiagnostics(fileName) {
        if (fileName) {
            return this.diagnostics.filter((f) => f.id === fileName);
        }
        return this.diagnostics;
    }
    updateByFileId(fileId, next) {
        for (let i = 0; i < this.diagnostics.length; i++) {
            if (this.diagnostics[i].id === fileId) {
                this.diagnostics.splice(i, 1);
                i--;
            }
        }
        if (next === null || next === void 0 ? void 0 : next.length) {
            this.diagnostics.push(...next);
        }
    }
}
exports.FileDiagnosticManager = FileDiagnosticManager;
