polyticket-api/poly-ticket-api-client/poly_ticket_api_client/models/patched_statement.py

266 lines
9.7 KiB
Python

from collections.abc import Mapping
from typing import Any, TypeVar, Union, cast
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from .. import types
from ..models.blank_enum import BlankEnum
from ..models.left_hand_operand_enum import LeftHandOperandEnum
from ..models.operator_enum import OperatorEnum
from ..types import UNSET, Unset
T = TypeVar("T", bound="PatchedStatement")
@_attrs_define
class PatchedStatement:
"""Serializer for the Statement model
Attributes:
event (Union[Unset, int]):
event_id (Union[Unset, int]):
id (Union[Unset, int]):
order (Union[Unset, int]): order between statements of the same condition
condition (Union[Unset, int]): a statement is linked to a condition, to 're-use' statement, use a condition
instead of a statement
left_hand_operand (Union[BlankEnum, LeftHandOperandEnum, Unset]):
left_hand_value (Union[Unset, str]): user defined value
operator (Union[BlankEnum, OperatorEnum, Unset]): with some left hand operands, the operator is unnecessary
* `>` - Greater
* `>=` - Greater Or Equal
* `=` - Equal
* `!=` - Not Equal
* `<` - Less
* `<=` - Less Or Equal
* `exists` - Exists
* `contains` - Contains
* `is in` - Is In
right_hand_value (Union[Unset, str]): right hand operand: User defined value (this can be an empty string with
Operator.EXISTS)
condition_as_statement (Union[None, Unset, int]): use a condition as a statement (nested condition)
"""
event: Union[Unset, int] = UNSET
event_id: Union[Unset, int] = UNSET
id: Union[Unset, int] = UNSET
order: Union[Unset, int] = UNSET
condition: Union[Unset, int] = UNSET
left_hand_operand: Union[BlankEnum, LeftHandOperandEnum, Unset] = UNSET
left_hand_value: Union[Unset, str] = UNSET
operator: Union[BlankEnum, OperatorEnum, Unset] = UNSET
right_hand_value: Union[Unset, str] = UNSET
condition_as_statement: Union[None, Unset, int] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
event = self.event
event_id = self.event_id
id = self.id
order = self.order
condition = self.condition
left_hand_operand: Union[Unset, str]
if isinstance(self.left_hand_operand, Unset):
left_hand_operand = UNSET
elif isinstance(self.left_hand_operand, LeftHandOperandEnum):
left_hand_operand = self.left_hand_operand.value
else:
left_hand_operand = self.left_hand_operand.value
left_hand_value = self.left_hand_value
operator: Union[Unset, str]
if isinstance(self.operator, Unset):
operator = UNSET
elif isinstance(self.operator, OperatorEnum):
operator = self.operator.value
else:
operator = self.operator.value
right_hand_value = self.right_hand_value
condition_as_statement: Union[None, Unset, int]
if isinstance(self.condition_as_statement, Unset):
condition_as_statement = UNSET
else:
condition_as_statement = self.condition_as_statement
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
if event is not UNSET:
field_dict["event"] = event
if event_id is not UNSET:
field_dict["event_id"] = event_id
if id is not UNSET:
field_dict["id"] = id
if order is not UNSET:
field_dict["order"] = order
if condition is not UNSET:
field_dict["condition"] = condition
if left_hand_operand is not UNSET:
field_dict["left_hand_operand"] = left_hand_operand
if left_hand_value is not UNSET:
field_dict["left_hand_value"] = left_hand_value
if operator is not UNSET:
field_dict["operator"] = operator
if right_hand_value is not UNSET:
field_dict["right_hand_value"] = right_hand_value
if condition_as_statement is not UNSET:
field_dict["condition_as_statement"] = condition_as_statement
return field_dict
def to_multipart(self) -> types.RequestFiles:
files: types.RequestFiles = []
if not isinstance(self.event, Unset):
files.append(("event", (None, str(self.event).encode(), "text/plain")))
if not isinstance(self.event_id, Unset):
files.append(("event_id", (None, str(self.event_id).encode(), "text/plain")))
if not isinstance(self.id, Unset):
files.append(("id", (None, str(self.id).encode(), "text/plain")))
if not isinstance(self.order, Unset):
files.append(("order", (None, str(self.order).encode(), "text/plain")))
if not isinstance(self.condition, Unset):
files.append(("condition", (None, str(self.condition).encode(), "text/plain")))
if not isinstance(self.left_hand_operand, Unset):
if isinstance(self.left_hand_operand, LeftHandOperandEnum):
files.append(("left_hand_operand", (None, str(self.left_hand_operand.value).encode(), "text/plain")))
else:
files.append(("left_hand_operand", (None, str(self.left_hand_operand.value).encode(), "text/plain")))
if not isinstance(self.left_hand_value, Unset):
files.append(("left_hand_value", (None, str(self.left_hand_value).encode(), "text/plain")))
if not isinstance(self.operator, Unset):
if isinstance(self.operator, OperatorEnum):
files.append(("operator", (None, str(self.operator.value).encode(), "text/plain")))
else:
files.append(("operator", (None, str(self.operator.value).encode(), "text/plain")))
if not isinstance(self.right_hand_value, Unset):
files.append(("right_hand_value", (None, str(self.right_hand_value).encode(), "text/plain")))
if not isinstance(self.condition_as_statement, Unset):
if isinstance(self.condition_as_statement, int):
files.append(
("condition_as_statement", (None, str(self.condition_as_statement).encode(), "text/plain"))
)
else:
files.append(
("condition_as_statement", (None, str(self.condition_as_statement).encode(), "text/plain"))
)
for prop_name, prop in self.additional_properties.items():
files.append((prop_name, (None, str(prop).encode(), "text/plain")))
return files
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
event = d.pop("event", UNSET)
event_id = d.pop("event_id", UNSET)
id = d.pop("id", UNSET)
order = d.pop("order", UNSET)
condition = d.pop("condition", UNSET)
def _parse_left_hand_operand(data: object) -> Union[BlankEnum, LeftHandOperandEnum, Unset]:
if isinstance(data, Unset):
return data
try:
if not isinstance(data, str):
raise TypeError()
left_hand_operand_type_0 = LeftHandOperandEnum(data)
return left_hand_operand_type_0
except: # noqa: E722
pass
if not isinstance(data, str):
raise TypeError()
left_hand_operand_type_1 = BlankEnum(data)
return left_hand_operand_type_1
left_hand_operand = _parse_left_hand_operand(d.pop("left_hand_operand", UNSET))
left_hand_value = d.pop("left_hand_value", UNSET)
def _parse_operator(data: object) -> Union[BlankEnum, OperatorEnum, Unset]:
if isinstance(data, Unset):
return data
try:
if not isinstance(data, str):
raise TypeError()
operator_type_0 = OperatorEnum(data)
return operator_type_0
except: # noqa: E722
pass
if not isinstance(data, str):
raise TypeError()
operator_type_1 = BlankEnum(data)
return operator_type_1
operator = _parse_operator(d.pop("operator", UNSET))
right_hand_value = d.pop("right_hand_value", UNSET)
def _parse_condition_as_statement(data: object) -> Union[None, Unset, int]:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(Union[None, Unset, int], data)
condition_as_statement = _parse_condition_as_statement(d.pop("condition_as_statement", UNSET))
patched_statement = cls(
event=event,
event_id=event_id,
id=id,
order=order,
condition=condition,
left_hand_operand=left_hand_operand,
left_hand_value=left_hand_value,
operator=operator,
right_hand_value=right_hand_value,
condition_as_statement=condition_as_statement,
)
patched_statement.additional_properties = d
return patched_statement
@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties