const authorizeAdminRoles = (
  ...allowedRoles
) => {
  const roleSet =
    new Set(
      allowedRoles
    );

  return (
    request,
    response,
    next
  ) => {
    if (!request.admin) {
      return response.status(401).json({
        success: false,
        message:
          "Administrator authentication is required."
      });
    }

    if (
      !roleSet.has(
        request.admin.role
      )
    ) {
      return response.status(403).json({
        success: false,
        message:
          "You do not have permission to perform this action."
      });
    }

    return next();
  };
};

module.exports = {
  authorizeAdminRoles
};