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

186 lines
5.5 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.mode_enum import ModeEnum
from ..types import UNSET, Unset
T = TypeVar("T", bound="NodePriceRule")
@_attrs_define
class NodePriceRule:
"""Serializer (read/write) for `NodePriceRule` model
Attributes:
event (int):
event_id (int):
id (int):
global_order (int):
order (int):
mode (ModeEnum): * `plus` - + [Current price + value]
* `set` - = [Set price to]
* `plus_percent` - +% [Current price + current price * value / 100]
* `multiply` - * [Current price * value]
* `divide` - / [Current price / value]
value (str):
label (str):
node_configuration_ids (list[int]):
condition_id (Union[Unset, int]):
should_propagate (Union[Unset, bool]): does this rule apply on children of the node
"""
event: int
event_id: int
id: int
global_order: int
order: int
mode: ModeEnum
value: str
label: str
node_configuration_ids: list[int]
condition_id: Union[Unset, int] = UNSET
should_propagate: Union[Unset, bool] = 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
global_order = self.global_order
order = self.order
mode = self.mode.value
value = self.value
label = self.label
node_configuration_ids = self.node_configuration_ids
condition_id = self.condition_id
should_propagate = self.should_propagate
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"event": event,
"event_id": event_id,
"id": id,
"global_order": global_order,
"order": order,
"mode": mode,
"value": value,
"label": label,
"node_configuration_ids": node_configuration_ids,
}
)
if condition_id is not UNSET:
field_dict["condition_id"] = condition_id
if should_propagate is not UNSET:
field_dict["should_propagate"] = should_propagate
return field_dict
def to_multipart(self) -> types.RequestFiles:
files: types.RequestFiles = []
files.append(("event", (None, str(self.event).encode(), "text/plain")))
files.append(("event_id", (None, str(self.event_id).encode(), "text/plain")))
files.append(("id", (None, str(self.id).encode(), "text/plain")))
files.append(("global_order", (None, str(self.global_order).encode(), "text/plain")))
files.append(("order", (None, str(self.order).encode(), "text/plain")))
files.append(("mode", (None, str(self.mode.value).encode(), "text/plain")))
files.append(("value", (None, str(self.value).encode(), "text/plain")))
files.append(("label", (None, str(self.label).encode(), "text/plain")))
for node_configuration_ids_item_element in self.node_configuration_ids:
files.append(
("node_configuration_ids", (None, str(node_configuration_ids_item_element).encode(), "text/plain"))
)
if not isinstance(self.condition_id, Unset):
files.append(("condition_id", (None, str(self.condition_id).encode(), "text/plain")))
if not isinstance(self.should_propagate, Unset):
files.append(("should_propagate", (None, str(self.should_propagate).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")
event_id = d.pop("event_id")
id = d.pop("id")
global_order = d.pop("global_order")
order = d.pop("order")
mode = ModeEnum(d.pop("mode"))
value = d.pop("value")
label = d.pop("label")
node_configuration_ids = cast(list[int], d.pop("node_configuration_ids"))
condition_id = d.pop("condition_id", UNSET)
should_propagate = d.pop("should_propagate", UNSET)
node_price_rule = cls(
event=event,
event_id=event_id,
id=id,
global_order=global_order,
order=order,
mode=mode,
value=value,
label=label,
node_configuration_ids=node_configuration_ids,
condition_id=condition_id,
should_propagate=should_propagate,
)
node_price_rule.additional_properties = d
return node_price_rule
@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