from msgbus import MBEasyContext
from typing import Optional

from mw import MwTableOrderRetriever, MsgBusTableService, RealClock
from reportsdata.tablereport import TableReportPresenter, TableReportGenerator
from reportsdata.tablereport.dto import TableReportFilterDto


class ReportGenerator(object):
    @staticmethod
    def generate(
        mb_context,                         # type: MBEasyContext
        pos_id,                             # type: str
        table_id,                           # type: str
        print_pre_account_by="TABLE",       # type: Optional[str]
        hide_unpriced_items="True",         # type: Optional[str]
        pre_account_with_discount=True,     # type: Optional[bool]
        filtered_seat=0                     # type: Optional[str]
    ):
        # type: (...) -> (TableReportGenerator, TableReportPresenter)

        table_order_retriever = MwTableOrderRetriever(MsgBusTableService())

        hide_unpriced_items = True if hide_unpriced_items == "True" else False
        pre_account_with_discount = True if pre_account_with_discount == "True" else False

        generator = TableReportGenerator(
                TableReportFilterDto(pos_id, table_id, None),
                RealClock(),
                table_order_retriever
        )

        presenter = TableReportPresenter(
            print_by=print_pre_account_by,
            hide_unpriced_items=hide_unpriced_items,
            pre_account_with_discount=pre_account_with_discount,
            pos_id=pos_id,
            filtered_seat=filtered_seat
        )

        return generator, presenter
