import { createHash } from "crypto";

/** Hash an IP address for privacy-preserving respondent tracking. */
export function hashIp(ip: string): string {
  const salt = process.env.IP_HASH_SALT;
  if (!salt && process.env.NODE_ENV === "production") {
    console.warn(
      "IP_HASH_SALT is not set — using insecure default. Set in production."
    );
  }
  const effectiveSalt = salt ?? "surveystronghold-dev-only";
  return createHash("sha256").update(`${effectiveSalt}:${ip}`).digest("hex");
}
