export const errorHandler = (err, req, res, next) => {
  console.error(err);

  const status = err.status || 500;
  const code = err.code || 'INTERNAL_SERVER_ERROR';
  const message = err.message || 'An unexpected error occurred';

  res.status(status).json({
    status: 'error',
    code,
    message,
    data: process.env.NODE_ENV === 'development' ? { error: err } : null
  });
};

export const notFoundHandler = (req, res) => {
  res.status(404).json({
    status: 'error',
    code: 'NOT_FOUND',
    message: `Route ${req.method} ${req.path} not found`,
    data: null
  });
};
