from typing import Optional

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


class SetGatewayStatus(AbstractStateUpdateHandler):
    HANDLER_KEY = "set_gateway_status"

    def get_new_state_kvs(self, data: dict) -> Optional[dict]:
        if not isinstance(status := data["status"], str):
            raise Exception("Invalid gateway status")
        if not isinstance(update := data["update"], int):
            raise Exception("Invalid update recommendation")
        return {"gateway_status": status, "gateway_update": update}
