"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MimeTypeRegistry = void 0;
const constants_1 = require("./constants");
class MimeTypeRegistry {
    constructor() {
        this.mimeTypesMap = (0, constants_1.getMimeTypesMap)();
        this.extensionsMap = new Map();
        for (const [mimeType, extensions] of Object.entries(this.mimeTypesMap)) {
            for (const extension of extensions) {
                this.extensionsMap.set(extension, mimeType);
            }
        }
    }
    getMimeTypeByExtension(extension) {
        return (this.extensionsMap.get(extension.toLowerCase().replace('.', '')) || null);
    }
    getExtensionsByMimeType(mimeType) {
        return this.mimeTypesMap[mimeType] || null;
    }
    static getInstance() {
        const instance = this.instanceRef?.deref();
        if (instance) {
            return instance;
        }
        const newInstance = new MimeTypeRegistry();
        this.instanceRef = new WeakRef(newInstance);
        return newInstance;
    }
}
exports.MimeTypeRegistry = MimeTypeRegistry;
