accounts/utils/clients/gooyal_promotions_client/models/promotion.py
2026-07-26 10:58:59 +03:30

129 lines
3.4 KiB
Python

from __future__ import annotations
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast
from uuid import UUID
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from ..models.state_enum import StateEnum
from ..types import UNSET, Unset
if TYPE_CHECKING:
from ..models.event import Event
T = TypeVar("T", bound="Promotion")
@_attrs_define
class Promotion:
"""
Attributes:
uuid (UUID):
event (Event):
user (UUID):
promotion_amount (int | None | Unset):
state (StateEnum | Unset): * `1` - created
* `2` - delayed
* `3` - pending
* `4` - incomplete
* `5` - success
* `6` - failed
* `7` - expected_failure
"""
uuid: UUID
event: Event
user: UUID
promotion_amount: int | None | Unset = UNSET
state: StateEnum | Unset = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
uuid = str(self.uuid)
event = self.event.to_dict()
user = str(self.user)
promotion_amount: int | None | Unset
if isinstance(self.promotion_amount, Unset):
promotion_amount = UNSET
else:
promotion_amount = self.promotion_amount
state: int | Unset = UNSET
if not isinstance(self.state, Unset):
state = self.state.value
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"uuid": uuid,
"event": event,
"user": user,
}
)
if promotion_amount is not UNSET:
field_dict["promotion_amount"] = promotion_amount
if state is not UNSET:
field_dict["state"] = state
return field_dict
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.event import Event
d = dict(src_dict)
uuid = UUID(d.pop("uuid"))
event = Event.from_dict(d.pop("event"))
user = UUID(d.pop("user"))
def _parse_promotion_amount(data: object) -> int | None | Unset:
if data is None:
return data
if isinstance(data, Unset):
return data
return cast(int | None | Unset, data)
promotion_amount = _parse_promotion_amount(d.pop("promotion_amount", UNSET))
_state = d.pop("state", UNSET)
state: StateEnum | Unset
if isinstance(_state, Unset):
state = UNSET
else:
state = StateEnum(_state)
promotion = cls(
uuid=uuid,
event=event,
user=user,
promotion_amount=promotion_amount,
state=state,
)
promotion.additional_properties = d
return promotion
@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