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

import sysactions
from bustoken import TK_POS_UPDATER_PERFORM_USER_UPDATE
from msgbus import TK_SYS_NAK, FM_PARAM
from actions.util.list_users import list_ids_opened_users
from utilfunctions import json_serialize


@sysactions.action
def update_users(pos_id):
    data = json_serialize(list_ids_opened_users())
    msg = sysactions.send_message("PosUpdater", TK_POS_UPDATER_PERFORM_USER_UPDATE, FM_PARAM, data)
    if msg.token == TK_SYS_NAK:
        message = "$UPDATE_USERS_" + msg.data.upper()
        sysactions.show_messagebox(pos_id, message, buttons="OK")
        return

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