import json

from application.interactor import GetEndPointsConfigInteractor
from messagebus import (
    DefaultToken,
    DataType,
    Message,
    MessageBus,
    AckMessage,
    Event,
    InternalErrorMessage,
)
from typing import (
    Any,
    Dict,
)
from ._NoErrorProcessor import NoErrorProcessor


class GetEndPointsConfigProcessor(NoErrorProcessor):
    def __init__(
        self,          # type: GetEndPointsConfigProcessor
        interactor,    # type: GetEndPointsConfigInteractor
    ):
        # type: (...) -> None

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

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

        return

    def call_business(
        self,       # type: GetEndPointsConfigProcessor
        request,    # type: Any
    ):
        # type: (...) -> Dict[str, bool]

        return self.interactor.get_loyalty_endpoints_config()

    def format_response(
        self,           # type: GetEndPointsConfigProcessor
        message_bus,    # type: MessageBus
        message,        # type: Message
        event,          # type: Event
        request,        # type: str
        response,       # type: str
    ):
        # type: (...) -> None

        message_bus.reply_message(
            message=message,
            reply_message=AckMessage(
                data_type=DataType.json,
                data=json.dumps(response),
            )
        )
