How to build the best medical image segmentation algorithm using foundation models: a comprehensive empirical study with Segment Anything Model