from typing import Optional

from clarabot_nano.core.state.update.base import AbstractStateUpdateHandler


class SetGatewayCommandResult(AbstractStateUpdateHandler):
    HANDLER_KEY = "set_gateway_command_result"

    def get_new_state_kvs(self, data: dict) -> Optional[dict]:
        if not isinstance(command_result := data["command_result"], str):
            raise Exception("Invalid gateway command result")
        return {
            "gateway_command_result": command_result,
            "gateway_command_result_number": self._s.get("gateway_command_result_number", 0) + 1,
        }
