from typing import Optional

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


class ServerLicenseValidity(AbstractStateUpdateHandler):
    HANDLER_KEY = "server_license_validity"

    def get_new_state_kvs(self, data: dict) -> Optional[dict]:
        if self._s.get("license") != data.get("license"):
            return {}  # ignore feedback for different license (new license has been set)
        validity = data.get("validity")
        if not isinstance(validity, str):
            raise Exception("Invalid validity")
        return {
            "license_server_validity": validity,
        }
