from logging import Logger

from production.box import CourseBox
from production.repository import ProductRepository
from typing import List, Optional, Union, Tuple, Any

from ._ProductionBox import ProductionBox


class CustomParamCourseBox(CourseBox):
    def __init__(self, name, sons, product_repository, publish_scheduler, logger=None):
        # type: (str, Optional[Union[List[ProductionBox]], ProductionBox], ProductRepository, List[Tuple[str, int]], Logger) -> None # noqa

        courses = product_repository.get_all_courses()
        course_products = product_repository.get_courses_products()
        configs = []
        if len(courses) > 0 and len(course_products) > 0:
            for course in courses:
                course_name = course.name
                description = course.description
                products = course_products[course_name] if course_name in course_products else {}
                configuration = CourseBox.CourseConfiguration(
                    name=course_name,
                    description=description,
                    products=products,
                    next_course_wait_time=course.delay,
                )
                configs.append(configuration)

        super(CustomParamCourseBox, self).__init__(name, sons, configs, publish_scheduler, logger)
