@dataclass
class Action:
action: str = ""
class Variant(Enum):
ACTION = "action"
IS_IGNORED = "is_ignored"
IS_ILLEGAL = "is_illegal"
WILL_BE_SET = "will_be_set"
IS_RESTRICTED = "is_restricted"
@classmethod
def from_dict(cls, d: dict[str, Any]) -> Action:
match d["variant"]:
case Action.Variant.ACTION.value:
return cls(d["action"])
case Action.Variant.IS_IGNORED.value:
return ParameterIsIgnored.from_dict(d)
case Action.Variant.IS_ILLEGAL.value:
return ParameterIsIllegal.from_dict(d)
case Action.Variant.WILL_BE_SET.value:
return ParameterWillBeSetTo.from_dict(d)
case Action.Variant.IS_RESTRICTED.value:
return ParameterIsRestricted.from_dict(d)
case _:
raise KeyError("unknown variant found")
def to_dict(self) -> dict[str, Any]:
return {"variant": Action.Variant.ACTION.value, "action": self.action}