from typing import OrderedDict
import six


def _extract_simplified_filter_fields(filter_fields):
    """
    Takes the filter_fields and simplifies them to a form django-filter can understand
    """
    # If we are just dealing with a list we are fine
    if not isinstance(filter_fields, dict):
        return filter_fields

    # if we are dealing with a dictionary we need to take all the fields and only store the lookups
    # (not the modified fields)
    _filter_fields = OrderedDict()

    for field_name, lookups in filter_fields.items():
        _filter_fields[field_name] = []
        for lookup in lookups:
            if isinstance(lookup, six.string_types):
                # if the lookup is a string then we are fine
                _filter_fields[field_name].append(lookup)
            else:
                # if the lookup is a tuple we need to only store the lookup string from it
                _filter_fields[field_name].append(lookup[0])

    return _filter_fields