from abc import (
    ABCMeta,
    abstractmethod,
)

from messagebus import (
    Message,
    MessageBus,
    Event,
    InternalErrorMessage,
)
from messageprocessorutil import UuidMessageProcessor


class NoErrorProcessor(UuidMessageProcessor):

    __metaclass__ = ABCMeta

    @abstractmethod
    def parse_data(self, data, event_type):
        raise NotImplementedError()

    @abstractmethod
    def call_business(self, obj):
        raise NotImplementedError()

    @abstractmethod
    def format_response(self, message_bus, message, event, input_obj, result):
        raise NotImplementedError()

    def format_exception(
        self,           # type: NoErrorProcessor
        message_bus,    # type: MessageBus
        message,        # type: Message
        event,          # type: Event
        input_obj,      # type: str
        exception,      # type: Exception
    ):
        # type: (...) -> None

        message_bus.reply_message(
            message=message,
            reply_message=InternalErrorMessage(exception),
        )

    def format_parse_exception(
        self,           # type: NoErrorProcessor
        message_bus,    # type: MessageBus
        message,        # type: Message
        event,          # type: Event
        data,           # type: bytes
        exception,      # type: Exception
    ):
        # type: (...) -> None

        self.format_exception(
            message_bus=message_bus,
            message=message,
            event=event,
            input_obj=data,
            exception=exception,
        )
