import logging
import json

from sysactions import send_message
from msgbus import FM_PARAM
from bustoken import TK_NCOUPON_GET_COUPON_INFO


class NCouponInteractor(object):
    def __init__(self):
        # type: () -> None
        self.logger = logging.getLogger("PosActions")

    @staticmethod
    def test_connection(
        pos_id,     # type: bool
    ):
        # type: (...) -> bool

        try:
            data = json.dumps({
                "posId": pos_id,
                "voucherId": "",
            })
            response = send_message("nCoupon", TK_NCOUPON_GET_COUPON_INFO, FM_PARAM, data, timeout=30000000)
            if response:
                return True
            return False
        except Exception as _:
            return False
