import json


def convert_saturation(max_saturation, saturation_mode, instrument, infile, target_acq_mode=False):
    """Converts full well fraction to a saturation in counts OR
    provides the max fullwell for TA mode.

    Parameters
    ----------
    max_saturation : float
        Either a full well fraction or counts
    saturation_mode : str
        ``well`` or ``counts``
    instrument : str
        The instrument
    infile : str
        The path to the data file
    target_acq_mode : bool, optional
        Whether or not it's TA mode

    Returns
    -------
    max_saturation : float
        The fullwell to use in counts.
    """

    with open(infile) as f:
        data = json.load(f)

    instrument_dict = data['fullwell']

    if saturation_mode == 'well':
        max_saturation = float(max_saturation) * float(instrument_dict[instrument])

    if target_acq_mode:
        max_saturation = instrument_dict[instrument]

    return max_saturation