from logging import Logger

from production.model import OrderChanger
from production.view import ProductionView
from ._OrderChangerProductionBox import OrderChangerProductionBox


class StampItemsViewBox(OrderChangerProductionBox):
    def __init__(self, name, order_changer, view, sons, logger=None):
        # type: (str, OrderChanger, ProductionView, str, Logger) -> None
        super(StampItemsViewBox, self).__init__(name, sons, logger)
        self.order_changer = order_changer
        self.view = view  # type: ProductionView

    def change_order(self, order):
        def stamp_item(item_to_change):
            if order.prod_state != "INVALID" and item_to_change.tags.get('kds_view') != self.view.view_name:
                return item_to_change.add_view(self.view.view_name)

        self.order_changer.change_items(order, stamp_item)

        return order
