import json

from messagebus import (
    AckMessage,
    InternalErrorMessage,
)
from messageprocessorutil import UuidMessageProcessor


class HealthCheckProcessor(UuidMessageProcessor):
    def parse_data(self):
        return None

    def call_business(self, obj):
        return {
            "status": "OK"
        }

    def format_response(self, message_bus, message, event, input_obj, result):
        message_bus.reply_message(
            message=message,
            reply_message=AckMessage(data=json.dumps(result).encode()),
        )

    def format_exception(self, message_bus, message, event, input_obj, exception):
        message_bus.reply_message(
            message=message,
            reply_message=InternalErrorMessage(ex=exception),
        )

    def format_parse_exception(self, message_bus, message, event, data, exception):
        self.format_exception(
            message_bus=message_bus,
            message=message,
            event=event,
            input_obj=data,
            exception=exception,
        )
