from ._OrderChangerProductionBox import OrderChangerProductionBox
from ..model import Item


class NotShowOnKitchenAddTagBox(OrderChangerProductionBox):

    def __init__(
        self,
        name,
        sons,
        tag_to_add,
        product_repository,
        logger=None,
    ):
        super(NotShowOnKitchenAddTagBox, self).__init__(
            name=name,
            sons=sons,
            logger=logger,
        )

        self.forbidden_part_codes = product_repository.get_not_show_on_kitchen()
        self.tag_to_add = tag_to_add

    def change_order(self, order):
        for item in order.items:
            self.handle_item(item)

        return order

    def handle_item(
        self,       # type: NotShowOnKitchenAddTagBox
        item,       # type: Item
    ):
        # type: (...) -> None

        if item.part_code in self.forbidden_part_codes:
            item.add_tag(self.tag_to_add)

        for son in item.items:
            self.handle_item(son)
