export const successResponse = (res, data, statusCode = 200) => {
  // Prevent caching for API responses to avoid stale data
  res.set({
    'Cache-Control': 'no-store, no-cache, must-revalidate, private',
    'Pragma': 'no-cache',
    'Expires': '0',
    'ETag': `"${Date.now()}-${Math.random()}"` // Unique ETag to prevent 304 responses
  });
  return res.status(statusCode).json({
    success: true,
    data,
  });
};

export const errorResponse = (res, message, statusCode = 400, errors = null) => {
  // Prevent caching for error responses
  res.set({
    'Cache-Control': 'no-store, no-cache, must-revalidate, private',
    'Pragma': 'no-cache',
    'Expires': '0',
  });
  const response = {
    success: false,
    error: message,
  };
  if (errors) {
    response.errors = errors;
  }
  return res.status(statusCode).json(response);
};

