from sysactions import get_used_service

from mbcontextmessagehandler import MbContextMessageBus
from messagebus import (
    Message,
    DataType,
)
from msgbus import TK_PRN_PRINT


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

        self.message_bus = message_bus

    def send_print_data(
        self,
        model,          # type: eTree
        response,       # type: str
    ):
        # type: (...) -> Message

        current_printer = get_used_service(
            model=model,
            service_type="printer",
        )

        message = Message(
            token=TK_PRN_PRINT,
            data_type=DataType.param,
            data=response,
        )

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