import { parseBooleanWithDefault } from "@open-mercato/shared/lib/boolean";
import { parseNumberWithDefault } from "@open-mercato/shared/lib/number";
const DEFAULT_SEARCH_MIN_TOKEN_LENGTH = 3;
const DEFAULT_BLOCKLIST = ["password", "token", "secret", "hash"];
function parseBoolean(raw, fallback) {
  return parseBooleanWithDefault(raw, fallback);
}
function parseNumber(raw, fallback, min = 1) {
  return parseNumberWithDefault(raw, fallback, { integer: true, min });
}
function parseHashAlgorithm(raw) {
  const value = (raw ?? "").trim().toLowerCase();
  if (value === "sha1") return "sha1";
  if (value === "md5") return "md5";
  return "sha256";
}
function resolveSearchConfig() {
  return {
    enabled: parseBoolean(process.env.OM_SEARCH_ENABLED, true),
    minTokenLength: resolveSearchMinTokenLength(),
    enablePartials: parseBoolean(process.env.OM_SEARCH_ENABLE_PARTIAL, true),
    hashAlgorithm: parseHashAlgorithm(process.env.OM_SEARCH_HASH_ALGO),
    storeRawTokens: parseBoolean(process.env.OM_SEARCH_STORE_RAW_TOKENS, false),
    blocklistedFields: (process.env.OM_SEARCH_FIELD_BLOCKLIST ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0).filter((value, index, arr) => arr.indexOf(value) === index).map((entry) => entry.toLowerCase()).concat(DEFAULT_BLOCKLIST).filter((value, index, arr) => arr.indexOf(value) === index)
  };
}
function resolveSearchMinTokenLength() {
  return parseNumber(process.env.OM_SEARCH_MIN_LEN, DEFAULT_SEARCH_MIN_TOKEN_LENGTH, 1);
}
export {
  DEFAULT_SEARCH_MIN_TOKEN_LENGTH,
  resolveSearchConfig,
  resolveSearchMinTokenLength
};
//# sourceMappingURL=config.js.map
