// 成功响应格式
const success = (data = null, message = '操作成功') => {
  return {
    success: true,
    code: 200,
    message,
    data,
    timestamp: new Date().toISOString()
  }
}

// 分页响应格式
const paginate = (data, pagination, message = '获取成功') => {
  return {
    success: true,
    code: 200,
    message,
    data: {
      list: data,
      pagination: {
        page: pagination.page,
        pageSize: pagination.pageSize,
        total: pagination.total,
        totalPages: Math.ceil(pagination.total / pagination.pageSize)
      }
    },
    timestamp: new Date().toISOString()
  }
}

// 错误响应格式
const error = (message = '操作失败', code = 400, errors = null) => {
  return {
    success: false,
    code,
    message,
    errors,
    timestamp: new Date().toISOString()
  }
}

// 创建成功响应
const created = (data = null, message = '创建成功') => {
  return {
    success: true,
    code: 201,
    message,
    data,
    timestamp: new Date().toISOString()
  }
}

// 无内容响应
const noContent = (message = '无内容') => {
  return {
    success: true,
    code: 204,
    message,
    data: null,
    timestamp: new Date().toISOString()
  }
}

module.exports = {
  success,
  paginate,
  error,
  created,
  noContent
}