from actions import mb_context
from bustoken import create_token
from msgbus import TK_SYS_ACK
from typing import Optional

IS_DELIVERY_FEE_ENABLED = None  # type: Optional[bool]
TK_REMOTE_ORDER_CHECK_IF_DELIVERY_FEE_IS_ENABLED = create_token("0", "37", "224")


def _get_delivery_fee_enabled_status():
    # type: () -> None

    global IS_DELIVERY_FEE_ENABLED

    msg = mb_context.MB_EasySendMessage("RemoteOrder", TK_REMOTE_ORDER_CHECK_IF_DELIVERY_FEE_IS_ENABLED)
    if msg.token == TK_SYS_ACK:
        IS_DELIVERY_FEE_ENABLED = True if msg.data == "True" else False


def is_delivery_fee_enabled():
    # type: () -> bool

    if IS_DELIVERY_FEE_ENABLED is None:
        _get_delivery_fee_enabled_status()

    return IS_DELIVERY_FEE_ENABLED
