// 统一响应格式工具
const responseFormat = {
  // 成功响应
  success: (data, message = 'success') => ({
    code: 200,
    status: 'success',
    data,
    message,
    timestamp: new Date().toISOString()
  }),
  
  // 错误响应
  error: (message, code = 500, data = null) => ({
    code,
    status: 'error',
    data,
    message,
    timestamp: new Date().toISOString()
  }),
  
  // 分页响应
  pagination: (data, pagination, message = 'success') => ({
    code: 200,
    status: 'success',
    data: data,
    pagination: {
      page: pagination.page,
      limit: pagination.limit,
      total: pagination.total,
      totalPages: Math.ceil(pagination.total / pagination.limit)
    },
    message,
    timestamp: new Date().toISOString()
  }),
  
  // 创建成功响应
  created: (data, message = '创建成功') => ({
    code: 201,
    status: 'success',
    data,
    message,
    timestamp: new Date().toISOString()
  }),
  
  // 无内容响应
  noContent: (message = '无内容') => ({
    code: 204,
    status: 'success',
    data: null,
    message,
    timestamp: new Date().toISOString()
  }),
  
  // 验证错误响应
  validationError: (errors, message = '验证失败') => ({
    code: 422,
    status: 'error',
    data: { errors },
    message,
    timestamp: new Date().toISOString()
  })
};

module.exports = responseFormat;