import base64
import gzip
import json


def decompress_metadata_string_to_dict(input_string):  # pylint: disable=invalid-name
    """
    Convert compact string format (dumped, gzipped, base64 encoded) from
    IonQ API metadata back into a dict relevant to building the results object
    on a returned job.

    Parameters:
        input_string (str): compressed string format of metadata dict

    Returns:
        dict: decompressed metadata dict
    """
    if input_string is None:
        return None
    encoded = input_string.encode()
    decoded = base64.b64decode(encoded)
    decompressed = gzip.decompress(decoded)
    return json.loads(decompressed)