import sysactions

from bustoken import TK_REMOTE_ORDER_INFORM_ORDER_READY
from msgbus import TK_SYS_ACK, FM_PARAM
from .. import mb_context


@sysactions.action
def inform_order_ready(pos_id, order_id):
    message = "$INFORM_ORDER_READY_CONFIRMATION"
    confirmation = sysactions.show_messagebox(pos_id, message, timeout=720000, buttons="$OK|$CANCEL")
    if confirmation == 1:
        return False

    msg = mb_context.MB_EasySendMessage("RemoteOrder", TK_REMOTE_ORDER_INFORM_ORDER_READY, FM_PARAM, order_id)
    if msg.token != TK_SYS_ACK:
        raise Exception("ACK not received from RemoteOrder when informing order ready " + order_id)
