import warnings


def get_scale_factor_and_appendStr(gc, slide_id, MPP=None, MAG=None):
    """Get how much is request region smaller than base.

    This also gets the string to append to server request for getting rgb.

    Parameters
    -----------
    gc : Girder client instance
        gc should be authoenticated.
    slide_id : str
        girder id of slide
    MPP : float or None
        Microns-per-pixel -- best use this as it's more well-defined than
        magnification which is more scanner/manufacturer specific.
        MPP of 0.25 often roughly translates to 40x
    MAG : float or None
        If you prefer to use whatever magnification is reported in slide.
        If neither MPP or MAG is provided, everything is retrieved without
        scaling at base (scan) magnification.

    Returns
    ----------
    float
        how much smaller (0.1 means 10x smaller) is requested image
        compared to scan magnification (slide coordinates)
    str
        string to appnd to server request for getting slide region

    """
    slide_info = gc.get("/item/%s/tiles" % slide_id)

    if (MPP is not None) and (slide_info['mm_x'] is not None):
        mm = 0.001 * MPP
        sf = slide_info['mm_x'] / mm
        appendStr = "&mm_x=%.4f&mm_y=%.8f" % (mm, mm)

    elif (MAG is not None) and (slide_info['magnification'] is not None):
        sf = MAG / slide_info['magnification']
        appendStr = "&magnification=%.8f" % MAG

    else:
        warnings.warn(
            "NO SLIDE MAGNIFICATION FOUND; BASE MAGNIFICATION USED!",
            RuntimeWarning)
        sf = 1.0
        appendStr = ""

    return sf, appendStr