from interactor import BaseInteractor
from messagebus import Message, DefaultToken, DataType
from messageprocessorutil import UuidMessageProcessor
from model.log import LogEntry


class EventProcessor(UuidMessageProcessor):
    def __init__(self, interactor):
        # type: (BaseInteractor) -> None
        super(EventProcessor, self).__init__()
        self.interactor = interactor

    def call_business(self, log_entry):
        # type: (LogEntry) -> None
        self.interactor.execute(log_entry)

    def format_response(self, message_bus, message, event, input_obj, result):
        message_bus.reply_event(event, Message(DefaultToken.TK_SYS_NAK))

    def format_exception(self, message_bus, message, event, input_obj, exception):
        message_bus.reply_event(event, Message(DefaultToken.TK_SYS_NAK))

    def format_parse_exception(self, message_bus, message, event, data, exception):
        message_bus.reply_event(event, Message(DefaultToken.TK_SYS_NAK))
