from typing import Optional
from messagebus import MessageBus, Event, Message
from ._SendMessageAdapter import SendMessageAdapter
from ._PublishEventAdapter import PublishEventAdapter


class LambdaMessageBus(MessageBus):
    def __init__(self, send_message_adapter, publish_event_adapter):
        # type: (Optional[SendMessageAdapter], Optional[PublishEventAdapter]) -> None
        self.send_message_adapter = send_message_adapter
        self.publish_event_adapter = publish_event_adapter

        self.reply = None

    def publish_event(self, event):
        # type: (Event) -> Message
        return self.publish_event_adapter.publish_event(event)

    def send_message(self, component, message):
        # type: (unicode, Message) -> Message
        return self.send_message_adapter.send_message(component, message)

    def subscribe(self, subject):
        # type: (unicode) -> None
        raise NotImplementedError()

    def reply_message(self, message, reply_message):
        # type: (Message, Message) -> None
        self.reply = reply_message

    def reply_event(self, event, reply_message):
        # type: (Event, Message) -> None
        self.reply = reply_message

    def get_reply(self):
        # type: () -> Dict
        return self.reply
