def map_to_ta_modes(ins, max_group, min_group):
    """Turns the min/max groups into the closest allowable
    TA group mode.

    Parameters
    ----------
    ins : str
        Instrument.
    max_group : int
        The maximum number of groups without oversaturating.
    
    min_group : int
        The groups needed to hit the target SNR.
    
    Returns
    -------
    min_ta_groups : int
        The min possible groups to hit target SNR.
    max_ta_groups : int
        The max possible groups before saturation.
    """

    # Allowable group modes for each ins
    groups = {'miri': [3, 5, 9, 15, 23, 33, 45, 59, 75, 93, 113, 135, 159, 185, 243, 275, 513],
              'niriss': [3, 5, 7, 9, 1, 13, 15, 17, 19],
              'nirspec': [3], 
              'nircam': [3, 5, 9, 17, 33, 65]
              }
    
    # Match the literal min and max groups to the nearest mode. 
    allowable_groups = groups[ins]
    min_ta_groups = min(allowable_groups, key=lambda x:abs(x-min_group))
    max_ta_groups = min(allowable_groups, key=lambda x:abs(x-max_group))
    
    # Unless it was oversaturated from the get-go OR there aren't enough groups
    # for SNR
    if min_group == 0:
        min_ta_groups = 0
        max_ta_groups = 0
    if min_group > max(allowable_groups):
        min_ta_groups = -1
        max_ta_groups = 0
    
    # BOTH ARE FLIPPED RN -- I WILL FLIP BOTH BACK SOON...
    return max_ta_groups, min_ta_groups