from msgbus import TK_PRN_PRINT

from messagebus import (
    DataType,
    Message,
    MessageBus,
)


class PrinterService(object):
    def __init__(
        self,
        message_bus,    # type: MessageBus
        timeout,        # type: int
    ):
        # type: (...) -> None

        self.message_bus = message_bus
        self.timeout = timeout

    def send_to_printer(
        self,
        printer_name,       # type: str
        text,               # type: str
    ):
        #  type: (...) -> Message

        message = Message(
            token=TK_PRN_PRINT,
            data_type=DataType.string,
            data=text,
            timeout=self.timeout,
        )

        return self.message_bus.send_message(
            component=printer_name,
            message=message,
        )

