import { createLogger } from "../logger.js";
const log = createLogger("providers");
let cached = null;
function getSearchProvider() {
  if (cached) return cached;
  const raw = process.env.WIGOLO_SEARCH;
  let which = raw === void 0 || raw === "" ? "core" : raw;
  if (which === "v1") {
    log.warn("WIGOLO_SEARCH=v1 is deprecated, use WIGOLO_SEARCH=core (alias kept for one release)");
    which = "core";
  }
  if (which === "searxng") {
    cached = import("../search/legacy/searxng-provider.js").then(
      (m) => {
        log.info("search provider selected", { provider: "searxng" });
        return new m.LegacySearxngProvider();
      },
      (err) => {
        cached = null;
        throw err;
      }
    );
  } else if (which === "core") {
    cached = import("../search/core/core-provider.js").then(
      (m) => {
        log.info("search provider selected", { provider: "core" });
        return new m.CoreSearchProvider();
      },
      (err) => {
        cached = null;
        throw err;
      }
    );
  } else if (which === "hybrid") {
    cached = (async () => {
      try {
        const [coreMod, sxMod, hybridMod] = await Promise.all([
          import("../search/core/core-provider.js"),
          import("../search/legacy/searxng-provider.js"),
          import("../search/hybrid/router.js")
        ]);
        log.info("search provider selected", { provider: "hybrid" });
        return new hybridMod.HybridSearchProvider(
          new coreMod.CoreSearchProvider(),
          new sxMod.LegacySearxngProvider()
        );
      } catch (err) {
        cached = null;
        throw err;
      }
    })();
  } else {
    return Promise.reject(new Error(
      `Unknown WIGOLO_SEARCH value: ${which}. Use 'core' (default), 'searxng', or 'hybrid'.`
    ));
  }
  return cached;
}
function _resetSearchProviderForTest() {
  cached = null;
}
export {
  _resetSearchProviderForTest,
  getSearchProvider
};
//# sourceMappingURL=search-provider.js.map