from typing import Any
from typing import Mapping
from typing import Counter
from typing import Iterable


def process_result(result) -> Any:
    """Make the result of a query JSON-serializable.

    Parameters
    ----------
    result :
        The result of a query

    Returns
    -------
    :
        The processed result
    """
    # Any fundamental type
    if isinstance(result, (int, str, bool, float)):
        return result
    # Any dict query
    elif isinstance(result, (dict, Mapping, Counter)):
        res_dict = dict(result)
        return {k: process_result(v) for k, v in res_dict.items()}
    # Any iterable query
    elif isinstance(result, (Iterable, list, set)):
        list_res = list(result)
        # Check for empty list
        if list_res and hasattr(list_res[0], "to_json"):
            list_res = [res.to_json() for res in list_res]
        return list_res
    else:
        raise TypeError(f"Don't know how to process result of type {type(result)}")