from commons.report import Generator
from deliveryreport import DeliveryReport
from deliveryreport.repository import (
    DeliveryOrderRepository,
    DeliveryProductRepository,
)
from dto import DeliveryHeaderDto, DeliveryBodyDto, DeliveryGeneratorDto


class DeliveryGenerator(Generator):
    def __init__(
        self,
        order_repository,       # type: DeliveryOrderRepository
        product_repository,     # type: DeliveryProductRepository
        order_id,               # type: str
        show_customer_phone,    # type: bool
    ):
        # type: (...) -> None

        self.order_repository = order_repository
        self.product_repository = product_repository
        self.order_id = order_id
        self.show_customer_phone = show_customer_phone

    def generate_data(self):
        delivery_report = DeliveryReport(self.order_repository, self.product_repository)
        order = delivery_report.get_delivery_order(self.order_id)
        products = delivery_report.get_products()
        cfh_products = delivery_report.get_cfh_products()
        header = DeliveryHeaderDto(order)
        body = DeliveryBodyDto(order)
        return DeliveryGeneratorDto(
            header=header,
            body=body,
            products=products,
            cfh_products=cfh_products,
            show_customer_phone=self.show_customer_phone,
        )
