from production.box import OrderSplitterBox
from production.treebuilder import BoxConfiguration

from ._BoxBuilder import BoxBuilder


class OrderSplitterBoxBuilder(BoxBuilder):
    def __init__(
        self,
        order_changer,
        publish_scheduler,
        loggers
    ):
        super(OrderSplitterBoxBuilder, self).__init__(loggers)
        self.order_changer = order_changer
        self.publish_scheduler = publish_scheduler
        self.split_type = None
        self.split_value = None

    def build(self, config):
        # type: (BoxConfiguration) -> OrderSplitterBox

        if u"SplitType" in config.extra_config:
            self.split_type = config.extra_config[u"SplitType"]
        if u"SplitValue" in config.extra_config:
            self.split_value = config.extra_config[u"SplitValue"]

        return OrderSplitterBox(
            config.name,
            config.sons,
            self.order_changer,
            self.publish_scheduler,
            self.split_type,
            self.split_value,
            self.get_logger(config)
        )
