import six


def _add_simplify(SingleActionType, BulkActionType):
  """
  Add .simplify method to "Bulk" actions, which returns None for no rows, non-Bulk version for a
  single row, and the original action otherwise.
  """
  if len(SingleActionType._fields) < 3:
    def get_first(self):
      return SingleActionType(self.table_id, self.row_ids[0])
  else:
    def get_first(self):
      return SingleActionType(self.table_id, self.row_ids[0],
                              { key: col[0] for key, col in six.iteritems(self.columns)})
  def simplify(self):
    return None if not self.row_ids else (get_first(self) if len(self.row_ids) == 1 else self)

  BulkActionType.simplify = simplify