# Path: ndlib/models/compartments/Compartment.py
# class Compartiment(object):
#     """
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.composed = None
#         if 'composed' in args[0]:
#             if isinstance(args[0]['composed'], Compartiment):
#                 self.composed = args[0]['composed']
# 
#     def execute(self, *args, **kwargs):
#         pass
# 
#     def compose(self, *args, **kwargs):
#         if self.composed is not None:
#             return self.composed.execute(*args, **kwargs)
#         else:
#             return True


from ndlib.models.compartments.Compartment import Compartiment

__author__ = 'Giulio Rossetti'
__license__ = "BSD-2-Clause"
__email__ = "giulio.rossetti@gmail.com"


class CountDown(Compartiment):

    def __init__(self, name, iterations, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.iterations = iterations
        self.name = name

    def execute(self, node, graph, status, status_map, *args, **kwargs):
        if self.name in graph.nodes[node]:
            graph.nodes[node][self.name] -= 1
        else:
            graph.nodes[node][self.name] = self.iterations

        test = graph.nodes[node][self.name] == 0
        if test:

# Path: ndlib/models/compartments/Compartment.py
# class Compartiment(object):
#     """
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.composed = None
#         if 'composed' in args[0]:
#             if isinstance(args[0]['composed'], Compartiment):
#                 self.composed = args[0]['composed']
# 
#     def execute(self, *args, **kwargs):
#         pass
# 
#     def compose(self, *args, **kwargs):
#         if self.composed is not None:
#             return self.composed.execute(*args, **kwargs)
#         else:
#             return True


# Path: ndlib/models/compartments/CountDown.py
from ndlib.models.compartments.Compartment import Compartiment


__author__ = 'Giulio Rossetti'
__license__ = "BSD-2-Clause"
__email__ = "giulio.rossetti@gmail.com"


class CountDown(Compartiment):

    def __init__(self, name, iterations, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.iterations = iterations
        self.name = name

    def execute(self, node, graph, status, status_map, *args, **kwargs):
        if self.name in graph.nodes[node]:
            graph.nodes[node][self.name] -= 1
        else:
            graph.nodes[node][self.name] = self.iterations

        test = graph.nodes[node][self.name] == 0
        if test:

            return self.compose(node, graph, status, status_map, kwargs)