def encoding(fields, use_original_field_names=False):
    """Convert fields structure to encoding maps for values and field names.
    Expects a fields dictionary structure, returns a tuple of two dictionaries where the keys are the field names
    (either original or new depending on the use_original_field_names parameter).
    Resulting dictionaries map the values for each field and field names.
    """
    encoding_map = {}
    encoding_field_names = {}
    for original_field_name, f in fields.items():
        if "encoding" in f:
            if f["encoding"].get("expand", True):
                if use_original_field_names:
                    key = original_field_name
                else:
                    key = f.get("name", original_field_name)

                encoding_field_names[key] = f["encoding"].get("name", f"{key}_")
                encoding_map[key] = f["encoding"].get("map", {})
    return encoding_map, encoding_field_names