const CONFIRM_OPTIONS = new Set(["apply_now", "plan_first", "analyze_only"]);

function envFlag(name) {
  const v = process.env[name];
  if (v === undefined || v === "") return null;
  return v;
}

function isDebugEnabled() {
  const v = envFlag("CAPINT_DEBUG");
  return v === "1" || v === "true";
}

function defaultConfirmOverride() {
  const v = envFlag("CAPINT_DEFAULT_CONFIRM");
  if (!v) return null;
  const normalized = v.trim().toLowerCase();
  if (!CONFIRM_OPTIONS.has(normalized)) return null;
  return normalized;
}

function logDebug(rootDir, payload) {
  if (!isDebugEnabled()) return;
  const extra = rootDir
    ? { disabled_overlay: require("./disabled-skills").disabledSet(rootDir).size }
    : {};
  console.error("[capint debug]", JSON.stringify({ ...payload, ...extra }, null, 0));
}

module.exports = {
  CONFIRM_OPTIONS,
  isDebugEnabled,
  defaultConfirmOverride,
  logDebug
};
