from messagebus import (
    AckMessage,
    DataType,
    NakMessage
)

from ._CommonProcessor import _CommonProcessor
from model import TestConnectionData


class TestConnectionProcessor(_CommonProcessor):
    def parse_data(self, data, event_type):
        return TestConnectionData(*data.split(';'))

    def call_business(self, test_connection_data):
        return self.payment_router.get_connection_status(test_connection_data)

    def format_response(self, message_bus, message, event, input_obj, result):
        if result:
            message_bus.reply_message(message, AckMessage(data=str(result), data_type=DataType.string))
        else:
            message_bus.reply_message(message, NakMessage())
