from messagebus import (
    AckMessage,
    Event,
    Message,
    MessageBus,
    NakMessage
)
from typing import Any

from ._CommonProcessor import _CommonProcessor


class GetNameProcessor(_CommonProcessor):
    def parse_data(
        self,
        data,           # type: str
        event_type,     # type: str
    ):
        # type: (...) -> str

        return data

    def call_business(
        self,
        pos_id,     # type: str
    ):
        # type: (...) -> str

        return self.payment_router.get_name()

    def format_response(
        self,
        message_bus,    # type: MessageBus
        message,        # type: Message
        event,          # type: Event
        input_obj,      # type: Any
        result,         # type: Any
    ):
        # type: (...) -> None

        message_bus.reply_message(
            message=message,
            reply_message=AckMessage(data=result),
        )

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

        self.payment_router._logger.exception("exception: {}".format(exception))
        message_bus.reply_message(
            message=message,
            reply_message=NakMessage(data=exception.message),
        )
