from logging import Logger

from production.box import ComboFilterBox
from production.treebuilder import BoxConfiguration
from production.repository import ProductRepository
from ._BoxBuilder import BoxBuilder


class ComboFilterBoxBuilder(BoxBuilder):
    def __init__(
        self,
        product_repository,     # type: ProductRepository
        loggers,                # type: Logger
    ):
        # type: (...) -> None

        super(ComboFilterBoxBuilder, self).__init__(loggers=loggers)
        self.product_repository = product_repository

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

        allowed_jit_lines = self.get_extra(config, "AllowedJitLines", None)
        items_to_keep = self.product_repository.get_items_to_show_on_jit(allowed_jit_lines=allowed_jit_lines)
        inherit_comments = self.get_extra(config, "InheritComments", "false").lower() == "true"
        return ComboFilterBox(
            name=config.name,
            sons=config.sons,
            items_to_keep=items_to_keep,
            inherit_comments=inherit_comments,
            logger=self.get_logger(config=config),
        )
