from typing import List

from report import Presenter  # noqa
from basereport import SimpleReport

from .builders import TableReportHeader, TableReportBody, ReportBuilder
from .dto import TableReportDto  # noqa


class TableReportPresenter(Presenter):
    def __init__(self, print_by, hide_unpriced_items, pre_account_with_discount, pos_id):
        self.print_by = print_by
        self.hide_unpriced_items = hide_unpriced_items
        self.pre_account_with_discount = pre_account_with_discount
        self.pos_id = pos_id

    def present(self, dto):
        # type: (TableReportDto) -> SimpleReport

        pos_id = self.pos_id
        report_builders = [
            TableReportHeader(dto.header, self.pre_account_with_discount),
            TableReportBody(dto.body, self.print_by, self.hide_unpriced_items, self.pre_account_with_discount, pos_id)
        ]  # type: List[ReportBuilder]

        report = []
        for builder in report_builders:
            report.extend(builder.generate())

        return SimpleReport(report, 38)
