"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PluginRepositoryCache", {
    enumerable: true,
    get: function() {
        return PluginRepositoryCache;
    }
});
const _envutils = require("../../utils/env.utils");
class PluginRepositoryCache {
    octoprintClient;
    logger;
    wasCached = false;
    pluginCache = [];
    lastQueried = undefined;
    constructor({ octoprintClient, loggerFactory }){
        this.octoprintClient = octoprintClient;
        this.logger = loggerFactory(PluginRepositoryCache.name);
    }
    getPlugin(pluginName) {
        if (!this.wasCached) {
            if (!(0, _envutils.isTestEnvironment)()) {
                this.logger.warn(`Could not check plugin '${pluginName}', as cache was not loaded`);
            }
            return;
        }
        return this.getCache().find((p)=>p.id.toLowerCase() === pluginName.toLowerCase());
    }
    getCache() {
        return [
            ...this.pluginCache
        ];
    }
    async queryCache() {
        this.pluginCache = await this.octoprintClient.fetchOctoPrintPlugins() || [];
        this.wasCached = true;
        this.lastQueried = Date.now();
        this.logger.log(`Plugin Cache filled with ${this.pluginCache?.length || "?"} plugins`);
        return this.getCache();
    }
}

//# sourceMappingURL=plugin-repository.cache.js.map