from datetime import datetime

from model.electronic_message import ElectronicMessage
from model.event import ListenedEvents
from typing import Any

from interactor.event import ElectronicPaymentEventInteractor
from messageprocessorutil import UuidMessageProcessor


class ElectronicPaymentShowQuestionProcessor(UuidMessageProcessor):

    def __init__(self, interactor):
        # type: (ElectronicPaymentEventInteractor) -> None

        super(ElectronicPaymentShowQuestionProcessor, self).__init__()
        self.interactor = interactor

    def parse_data(self, data, event_type):
        # type: (Any, str) -> ElectronicMessage

        pos_id, message, title, buttons = data.split("\\0")

        electronic_message = ElectronicMessage(
            pos_id=pos_id,
            event_type=ListenedEvents.ELECTRONIC_PAYMENT_SHOW_QUESTION,
            title=title,
            timestamp=datetime.now().isoformat(),
            buttons=buttons,
            message_data=message
        )
        return electronic_message

    def call_business(self, electronic_message):
        # type: (ElectronicMessage) -> None

        self.interactor.queue_message(electronic_message)

    def format_response(self, message_bus, message, event, input_obj, result):
        pass

    def format_exception(self, message_bus, message, event, input_obj, exception):
        pass

    def format_parse_exception(self, message_bus, message, event, data, exception):
        pass
