from typing import OrderedDict


def _Net_get_id_name(func, field):
    """
    Generic property that maps func to the layer names into an OrderedDict.

    Used for top_names and bottom_names.

    Parameters
    ----------
    func: function id -> [id]
    field: implementation field name (cache)

    Returns
    ------
    A one-parameter function that can be set as a property.
    """
    @property
    def get_id_name(self):
        if not hasattr(self, field):
            id_to_name = list(self.blobs)
            res = OrderedDict([(self._layer_names[i],
                                [id_to_name[j] for j in func(self, i)])
                                for i in range(len(self.layers))])
            setattr(self, field, res)
        return getattr(self, field)
    return get_id_name