import json

from messageprocessorutil import UuidMessageProcessor
from ._AsyncResponseInteractor import AsyncResponseInteractor
from .dto import AsyncResponseRequest


class AsyncResponseProcessor(UuidMessageProcessor):
    def __init__(
        self,
        interactor: AsyncResponseInteractor,
    ):
        super().__init__()

        self.interactor = interactor

    def parse_data(self, event, data):
        data_dict = json.loads(data.decode("utf-8"))
        return AsyncResponseRequest(
            subject=event.subject,
            data=data_dict,
        )

    def call_business(self, request: AsyncResponseRequest):
        self.interactor.process_async_response(request=request)

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

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

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