from typing import Optional

from actions.config import get_pre_account_allow_printing
from actions.printer import nreports_preview_and_print
from api.nreports import get_nreports_service
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(posid=pos_id)
    order = get_current_order(model=model)
    is_mobile = is_mobile.lower() == "true" if isinstance(is_mobile, str) else is_mobile

    print_data = get_nreports_service().pre_account_quick_service(
        pos_id=pos_id,
        order_id=order.get("orderId"),
        is_mobile=is_mobile,
    )
    nreports_preview_and_print.print_preview_report(
        pos_id=pos_id,
        report_data=print_data,
        preview=True,
        order=order,
        allow_printing=get_pre_account_allow_printing(),
    )
