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

import sysactions
from bustoken import TK_POS_UPDATER_PERFORM_USER_UPDATE
from msgbus import TK_SYS_NAK, FM_PARAM

from actions.update import show_nak_message
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:
        response_message = msg.data
        show_nak_message(pos_id, "$UPDATE_USERS_", response_message)

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