const { HTTP_STATUS } = require("../config/constants");

const sendSuccess = (res, data = {}, statusCode = HTTP_STATUS.OK) => {
  res.status(statusCode).json({
    success: true,
    ...data,
  });
};

const sendError = (
  res,
  message = "Server error",
  statusCode = HTTP_STATUS.INTERNAL_ERROR
) => {
  res.status(statusCode).json({
    success: false,
    message,
  });
};

const sendNotFound = (res, resource = "Resource") => {
  res.status(HTTP_STATUS.NOT_FOUND).json({
    success: false,
    message: `${resource} not found`,
  });
};

const sendUnauthorized = (res, message = "Authentication required") => {
  res.status(HTTP_STATUS.UNAUTHORIZED).json({
    success: false,
    message,
  });
};

const sendForbidden = (res, message = "Access denied") => {
  res.status(HTTP_STATUS.FORBIDDEN).json({
    success: false,
    message,
  });
};

module.exports = {
  sendSuccess,
  sendError,
  sendNotFound,
  sendUnauthorized,
  sendForbidden,
};
