import reportactions

from actions.config import (
    get_hide_unpriced_items_from_total_report,
    get_pre_account_with_discount,
    get_pre_account_allow_printing,
)
from typing import (
    Optional,
)
from sysactions import (
    action,
    get_model,
    get_current_order,
)


@action
def qsr_totaled_total_report(
    pos_id,                         # type: str
    is_mobile=False,                # type: Optional[bool]
):
    # type: (...) -> None

    model = get_model(pos_id)
    order = get_current_order(model)

    table_id = None
    print_pre_account_by = "qsr"
    order_is_totaled = order is not None and order.get("state") == "TOTALED"
    filter_seat = "0"

    reportactions.print_report(
        pos_id=pos_id,
        report_name="table_report",
        order=order,
        allow_printing=get_pre_account_allow_printing(),
        is_mobile=is_mobile.lower() == "true" if isinstance(is_mobile, basestring) else is_mobile,
        report_args=[
            table_id,
            order.get("orderId"),
            print_pre_account_by,
            get_hide_unpriced_items_from_total_report(),
            get_pre_account_with_discount() or order_is_totaled,
            filter_seat,
        ],
    )
