import { bytesToHex } from '@/lib/encoding.js';

/**
 * Notification observability helpers.
 *
 * PII-safe: userId is hashed to a 16-hex truncated SHA-256 before logging.
 * Never log message bodies or personal data.
 */

/**
 * Hash a userId to a 16-hex truncated SHA-256 for structured logging.
 * Consistent across requests — usable for cross-log correlation without exposing PII.
 */
export async function hashUserId(userId: string): Promise<string> {
  const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(userId));
  return bytesToHex(buf).slice(0, 16);
}
