from typing import Any

from messagebus import (
    AckMessage,
    Event,
    Message,
    MessageBus,
    NakMessage,
)
from messageprocessorutil import UuidMessageProcessor

from services.interactor import UpdateAlertsInteractor


class UpdateAlertsProcessor(UuidMessageProcessor):
    def __init__(
        self,
        update_alerts_interactor,  # type: UpdateAlertsInteractor
    ):
        # type: (...) -> None

        super(UpdateAlertsProcessor, self).__init__()
        self.update_alerts_interactor = update_alerts_interactor

    def parse_data(
        self,
        data,           # type: str
        event_type,     # type: str
    ):
        # type: (...) -> None

        return None

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

        return self.update_alerts_interactor.process_request()

    def format_response(
        self,
        message_bus,    # type: MessageBus
        message,        # type: Message
        event,          # type: Event
        request,        # type: None
        result,         # type: None
    ):
        # 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: None
        exception,      # type: Exception
    ):
        # type: (...) -> None

        message_bus.reply_message(
            message=message,
            reply_message=NakMessage(data=exception.message),
        )

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

        message_bus.reply_message(
            message=message,
            reply_message=NakMessage(data=exception.message),
        )
