import gzip
import pickle
import difflib


def get_model(model_id):
    """
    Return sets of Inchikeys and names associated with the model id
    :param model_id: the name of the metabolic model
    :type model_id: str
    :return:
    :rtype: tuple(set, set)
    """
    def get_set(file):
        with gzip.GzipFile(file, 'rb') as infile:
            set_dict = pickle.load(infile)
        try:
            return set_dict[model_id]
        except KeyError:
            options = difflib.get_close_matches(model_id, set_dict.keys())
            raise ValueError('%s does not match any valid models. Did you '
                             'mean any of these: %s'
                             % (model_id, ", ".join(options)))

    return get_set('model_inchikeys.pkl.gz'), get_set('model_names.pkl.gz')