import collections


def _check_enum(enums):
    """Check the collected enums

    Args:
        enums (dict of str: list[str]): mapping from the path to the enum to the enum object

    Returns:
        dict: mapping from the violations and the corresponding path (and item name if necessary)

    """
    check_result = collections.defaultdict(list)
    for path, enum_list in enums.items():
        if not isinstance(enum_list, list):
            check_result["enum not a list"].append(path)

        for item in enum_list:
            if not isinstance(item, str):
                check_result["enum item is not a string"].append("{}: {}".format(path, item))

        if len(set(enum_list)) < len(enum_list):
            check_result["duplicates in enum"].append(path)
            duplicates = [item for item, count in collections.Counter(enum_list).items() if count > 1]
            for item in duplicates:
                check_result["duplicates in enum"].append("\t{}".format(item))
    return check_result