import json

import sysactions

from bustoken import (
    TK_RUPTURA_GET_DAILY_DISHES,
    TK_RUPTURA_GET_DISABLED,
    TK_RUPTURA_GET_ENABLED
)
from model.customexception import GetRuptureItemsException
from msgbus import TK_SYS_NAK, FM_STRING
from typing import Dict


def get_disabled_products():
    msg = sysactions.send_message("Ruptura", TK_RUPTURA_GET_DISABLED, FM_STRING, "UI")

    if msg.token == TK_SYS_NAK:
        raise GetRuptureItemsException("Error getting rupture disable products")

    return json.loads(msg.data)


def get_enabled_products():
    msg = sysactions.send_message("Ruptura", TK_RUPTURA_GET_ENABLED, FM_STRING, "UI")
    if msg.token == TK_SYS_NAK:
        raise GetRuptureItemsException("Error getting rupture enabled products")

    return json.loads(msg.data)


def get_daily_dishes():
    # type: (...) -> Dict

    msg = sysactions.send_message(
        dest_name="Ruptura",
        token=TK_RUPTURA_GET_DAILY_DISHES,
        format=FM_STRING
    )

    if msg.token == TK_SYS_NAK:
        raise GetRuptureItemsException("Error getting rupture daily dishes")

    return json.loads(msg.data)
