import warnings


def slab_filter(config, dask_dict):
    """
    Filters a dask bag `dask_dict` of slabs according to rules specified in config yml `config`
        Args:
        config: dictionary of the config yaml
        dask_dict: a dictionary containing slab info

    Returns:
        boolean value (True -> retain slab, False -> reject slab)
    """
    slab_filters = config["slab_filters"]

    keep = True

    for name, val in slab_filters.items():
        if val != "None":
            if name == "filter_by_object_size":
                keep = keep and (dask_dict["slab_natoms"] <= val)
            elif name == "filter_by_max_miller_index":
                keep = keep and (dask_dict["slab_max_miller_index"] <= val)
            else:
                warnings.warn("Slab filter is not implemented: " + name)
    return keep