from production.treebuilder import BoxConfiguration

from ._BoxBuilder import BoxBuilder
from production.box import TagFilterBox


class TagFilterBoxBuilder(BoxBuilder):
    def __init__(self, loggers):
        super(TagFilterBoxBuilder, self).__init__(loggers)

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

        inherit_comments = self.get_extra(config, "InheritComments", "false").lower() == "true"

        return TagFilterBox(
            name=config.name,
            sons=config.sons,
            allowed_tags=self.get_extra(config, "AllowedTags", None),
            forbidden_tags=self.get_extra(config, "ForbiddenTags", None),
            allow_combos=self.get_extra(config, "AllowComboTags", 'False'),
            inherit_comments=inherit_comments,
            logger=self.get_logger(config),
        )
