import { createLogger } from "../logger.js";
const log = createLogger("server");
class PluginRegistry {
  extractors = [];
  engines = [];
  pluginNames = /* @__PURE__ */ new Set();
  registerExtractor(extractor, pluginName) {
    if (this.extractors.some((r) => r.extractor.name === extractor.name)) {
      log.warn("duplicate extractor name, ignoring", {
        name: extractor.name,
        plugin: pluginName
      });
      return;
    }
    this.extractors.push({ extractor, pluginName });
    this.pluginNames.add(pluginName);
    log.debug("registered plugin extractor", {
      name: extractor.name,
      plugin: pluginName
    });
  }
  registerSearchEngine(engine, pluginName) {
    if (this.engines.some((r) => r.engine.name === engine.name)) {
      log.warn("duplicate search engine name, ignoring", {
        name: engine.name,
        plugin: pluginName
      });
      return;
    }
    this.engines.push({ engine, pluginName });
    this.pluginNames.add(pluginName);
    log.debug("registered plugin search engine", {
      name: engine.name,
      plugin: pluginName
    });
  }
  getExtractors() {
    return this.extractors.map((r) => r.extractor);
  }
  getSearchEngines() {
    return this.engines.map((r) => r.engine);
  }
  getExtractorByName(name) {
    return this.extractors.find((r) => r.extractor.name === name)?.extractor;
  }
  getSearchEngineByName(name) {
    return this.engines.find((r) => r.engine.name === name)?.engine;
  }
  getState() {
    return {
      extractors: this.extractors.map((r) => ({
        name: r.extractor.name,
        pluginName: r.pluginName
      })),
      searchEngines: this.engines.map((r) => ({
        name: r.engine.name,
        pluginName: r.pluginName
      })),
      pluginCount: this.pluginNames.size
    };
  }
  clear() {
    this.extractors = [];
    this.engines = [];
    this.pluginNames.clear();
  }
}
export {
  PluginRegistry
};
//# sourceMappingURL=registry.js.map