import pyscripts
import sysactions

from bustoken import TK_SLCTRL_PMGR_GET_MODIFIERS
from msgbus import (
    FM_PARAM,
    TK_SYS_ACK,
)
from posot import OrderTakerException


mb_context = pyscripts.mbcontext
_modifiers = None


@sysactions.action
def get_modifiers_data(_):

    global _modifiers

    if _modifiers is None:
        message_response = mb_context.MB_EasySendMessage(
            dest_name='ORDERMGR',
            token=TK_SLCTRL_PMGR_GET_MODIFIERS,
            format=FM_PARAM,
        )
        if message_response.token != TK_SYS_ACK:
            raise OrderTakerException(
                code=-1,
                descr=message_response.data,
            )
        _modifiers = message_response.data

    return _modifiers
