import { createLogger } from "../../../logger.js";
const log = createLogger("cli");
const PASSTHROUGH_KEYS = /* @__PURE__ */ new Set([
  "browserTypes",
  "dataDir",
  "cacheTtlSearch"
]);
const RENAMED_KEYS = {
  WIGOLO_SEARCH: "searchBackend"
};
const KNOWN_OUTPUT_KEYS = /* @__PURE__ */ new Set([
  ...PASSTHROUGH_KEYS,
  ...Object.values(RENAMED_KEYS),
  "llmProvider",
  "llmKeyLocation"
]);
function migrateV1ToV2(input) {
  if (input.version === 2) {
    return input;
  }
  const v1 = input;
  const out = {};
  const legacy = {};
  for (const [key, value] of Object.entries(v1.settings ?? {})) {
    if (PASSTHROUGH_KEYS.has(key)) {
      out[key] = value;
      continue;
    }
    if (Object.prototype.hasOwnProperty.call(RENAMED_KEYS, key)) {
      const renamed = RENAMED_KEYS[key];
      out[renamed] = value;
      continue;
    }
    if (KNOWN_OUTPUT_KEYS.has(key)) {
      out[key] = value;
      continue;
    }
    legacy[key] = value;
    log.warn("migrate: unknown legacy setting preserved under __legacy", {
      key
    });
  }
  if (v1.provider) {
    if (v1.provider.name !== void 0) {
      out["llmProvider"] = v1.provider.name;
    }
    if (v1.provider.keyLocation !== void 0) {
      out["llmKeyLocation"] = v1.provider.keyLocation;
    }
  }
  if (Object.keys(legacy).length > 0) {
    out["__legacy"] = legacy;
  }
  return {
    version: 2,
    settings: out
  };
}
export {
  migrateV1ToV2
};
//# sourceMappingURL=migrate.js.map