from msgbus import TK_SYS_ACK
from sysactions import (
    action,
    send_message,
    show_messagebox,
)
from mw_helper import show_numpad_dialog
from bustoken import (
    create_token,
    MSGPRT_LOW,
)


TK_PUMP_RETRANSMIT_ORDERS = create_token(
    priority=MSGPRT_LOW,
    message_grourp="B",
    number="1",
)


@action
def retransmit_orders(
    pos_id,    # type: str
):
    # type: (...) -> None

    order_id = show_numpad_dialog(
        pos_id=pos_id,
        title="$INSERT_ORDER_ID",
        message="",
        mask="",
    )
    if order_id is None:
        return

    reply = send_message(
        dest_name="bohpump",
        token=TK_PUMP_RETRANSMIT_ORDERS,
        data=str(order_id),
        timeout=30000000,
    )
    if reply.token == TK_SYS_ACK:
        show_messagebox(
            posid=pos_id,
            message="$RETRANSMIT_ORDER_SUCCESS",
        )
        return

    show_messagebox(
        posid=pos_id,
        message="$RETRANSMIT_ORDER_ERROR",
    )
