# Path: pypipeline/core/Status.py
# class Status(Enum):
#     starting = 1
#     stopping = 2
#     running = 3
#     stopped = 4
# 
# Path: pypipeline/core/Exchange.py
# class Exchange:
#     def __init__(self):
#         self.id = uuid.uuid4()
#         self.in_msg = None
#         self.out_msg = None
#         self.properties = {}
# 
#     def __str__(self):
#         return "Id: " + str(self.id) + "\nProperties: " + str(self.properties) + "\nIn Msg:\n" + str(self.in_msg) + "\nOut Msg:\n" + str(self.out_msg)
# 
# Path: pypipeline/core/PipelineBuilder.py
# class PipelineBuilder:
#     def __init__(self):
#         self.source_class = None
#         self.source_params = None
#         self.to_list = []
#         self.id = None
#         self.auto_start = True
# 
#     def build(self):
#         raise NotImplementedError
# 
#     def build_with_plumber(self, plumber):
#         raise NotImplementedError


from .Status import Status
from .Exchange import Exchange
from .PipelineBuilder import PipelineBuilder


class Plumber:
    def __init__(self):
        self.pipelines = {}
        self.state = Status.stopped

    def create_exchange(self):
        exchange = Exchange()
        exchange.plumber = self
        return exchange

    def start(self):
        self.state = Status.starting
        for pipeline_id, pipeline in self.pipelines.items():
            self._start_pipeline(pipeline)
        self.state = Status.running

    def stop(self):
        self.state = Status.stopping
        for pipeline_id, pipeline in self.pipelines.items():
            self._stop_pipeline(pipeline)
        self.state = Status.stopped

    def add_pipeline(self, pipeline):
        if isinstance(pipeline, PipelineBuilder):
            pipeline = pipeline.build_with_plumber(self)
        if pipeline.id is None:
            pipeline.id = "pipeline" + str(len(self.pipelines) - 1)
        self.pipelines[pipeline.id] = pipeline

# Path: pypipeline/core/Status.py
# class Status(Enum):
#     starting = 1
#     stopping = 2
#     running = 3
#     stopped = 4
# 
# Path: pypipeline/core/Exchange.py
# class Exchange:
#     def __init__(self):
#         self.id = uuid.uuid4()
#         self.in_msg = None
#         self.out_msg = None
#         self.properties = {}
# 
#     def __str__(self):
#         return "Id: " + str(self.id) + "\nProperties: " + str(self.properties) + "\nIn Msg:\n" + str(self.in_msg) + "\nOut Msg:\n" + str(self.out_msg)
# 
# Path: pypipeline/core/PipelineBuilder.py
# class PipelineBuilder:
#     def __init__(self):
#         self.source_class = None
#         self.source_params = None
#         self.to_list = []
#         self.id = None
#         self.auto_start = True
# 
#     def build(self):
#         raise NotImplementedError
# 
#     def build_with_plumber(self, plumber):
#         raise NotImplementedError


# Path: pypipeline/core/Plumber.py
from .Status import Status
from .Exchange import Exchange
from .PipelineBuilder import PipelineBuilder



class Plumber:
    def __init__(self):
        self.pipelines = {}
        self.state = Status.stopped

    def create_exchange(self):
        exchange = Exchange()
        exchange.plumber = self
        return exchange

    def start(self):
        self.state = Status.starting
        for pipeline_id, pipeline in self.pipelines.items():
            self._start_pipeline(pipeline)
        self.state = Status.running

    def stop(self):
        self.state = Status.stopping
        for pipeline_id, pipeline in self.pipelines.items():
            self._stop_pipeline(pipeline)
        self.state = Status.stopped

    def add_pipeline(self, pipeline):
        if isinstance(pipeline, PipelineBuilder):
            pipeline = pipeline.build_with_plumber(self)
        if pipeline.id is None:
            pipeline.id = "pipeline" + str(len(self.pipelines) - 1)
        self.pipelines[pipeline.id] = pipeline

        if pipeline.auto_start and self.state in (Status.running, Status.starting):