from production.box import CustomParamCourseBox
from production.treebuilder import BoxConfiguration

from ._BoxBuilder import BoxBuilder


class CustomParamCourseBoxBuilder(BoxBuilder):
    def __init__(self, product_repository, publish_scheduler, loggers):
        super(CustomParamCourseBoxBuilder, self).__init__(loggers)
        self.product_repository = product_repository
        self.publish_scheduler = publish_scheduler

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

        return CustomParamCourseBox(
                config.name,
                config.sons,
                self.product_repository,
                self.publish_scheduler,
                self.get_logger(config)
        )

    @staticmethod
    def course_comparer(c1, c2):
        return int(c1[2]) - int(c2[2])
