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

import sysactions

from bustoken import TK_POS_UPDATER_PERFORM_MEDIA_UPDATE
from msgbus import TK_SYS_NAK, FM_PARAM

from actions.update.update_util import show_nak_message


@sysactions.action
def update_media(pos_id):
    msg = sysactions.send_message("PosUpdater", TK_POS_UPDATER_PERFORM_MEDIA_UPDATE, FM_PARAM, timeout=60000000 * 5)
    if msg.token == TK_SYS_NAK:
        if not msg.data:
            sysactions.show_messagebox(pos_id, "$UPDATE_MEDIA_DISABLED" + msg.data.upper(), buttons="OK")
            return
        else:
            response_message = msg.data
            show_nak_message(pos_id, "$UPDATE_MEDIA_", response_message)

    sysactions.show_messagebox(pos_id, "$UPDATE_MEDIA_MESSAGE", buttons="OK")
