function getClientIp(req) {
  const forwarded = req.headers["x-forwarded-for"];

  if (forwarded) {
    return forwarded.split(",")[0].trim();
  }

  return req.socket?.remoteAddress || req.connection?.remoteAddress || null;
}

function getUserAgent(req) {
  return req.headers["user-agent"] || "";
}

module.exports = {
  getClientIp,
  getUserAgent,
};
