# -*- coding: utf-8 -*-

from sysactions import action, show_messagebox # noqa
from bustoken import TK_POS_UPDATER_PERFORM_BINARIES_UPDATE
from msgbus import TK_SYS_NAK # noqa

from .. import mb_context


@action
def update_binaries(pos_id):

    resp = show_messagebox(pos_id, "$UPDATE_BINARIES_MESSAGE_QUESTION", buttons="$OK|$CANCEL")
    if resp == 1:
        return

    timeout = 60000000 * 20
    binary_update_token = TK_POS_UPDATER_PERFORM_BINARIES_UPDATE
    msg = mb_context.MB_EasySendMessage("PosUpdater", binary_update_token, timeout=timeout)
    if msg.token == TK_SYS_NAK:
        show_messagebox(pos_id, "$UPDATE_BINARIES_" + msg.data.upper(), buttons="OK")
        return

    show_messagebox(pos_id, "$UPDATE_BINARIES_MESSAGE", buttons="OK")
