from logging import Logger

from typing import Dict

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


class ItemCustomParamsFilterBoxBuilder(BoxBuilder):
    def __init__(
        self,                   # type: ItemCustomParamsFilterBoxBuilder
        product_repository,     # type: ProductRepository
        loggers,                # type: Dict[str, Logger]
    ):
        # type: (...) -> None

        super(ItemCustomParamsFilterBoxBuilder, self).__init__(loggers=loggers)

        self.product_repository = product_repository

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

        return ItemCustomParamsFilterBox(
            name=config.name,
            sons=config.sons,
            product_repository=self.product_repository,
            custom_params=self.get_extra(config, "CustomParams", None),
            inherit_comments=self.get_extra(config, "InheritComments", "false").lower() == "true",
            logger=self.get_logger(config=config),
        )
