from collections.abc import Mapping from typing import TYPE_CHECKING, Any, TypeVar, Union, cast from attrs import define as _attrs_define from attrs import field as _attrs_field from ..types import UNSET, Unset if TYPE_CHECKING: from ..models.account import Account T = TypeVar("T", bound="PaginatedAccountList") @_attrs_define class PaginatedAccountList: """ Attributes: count (int): Example: 123. results (list['Account']): next_ (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=400&limit=100. previous (Union[None, Unset, str]): Example: http://api.example.org/accounts/?offset=200&limit=100. """ count: int results: list["Account"] next_: Union[None, Unset, str] = UNSET previous: Union[None, Unset, str] = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: count = self.count results = [] for results_item_data in self.results: results_item = results_item_data.to_dict() results.append(results_item) next_: Union[None, Unset, str] if isinstance(self.next_, Unset): next_ = UNSET else: next_ = self.next_ previous: Union[None, Unset, str] if isinstance(self.previous, Unset): previous = UNSET else: previous = self.previous field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "count": count, "results": results, } ) if next_ is not UNSET: field_dict["next"] = next_ if previous is not UNSET: field_dict["previous"] = previous return field_dict @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.account import Account d = dict(src_dict) count = d.pop("count") results = [] _results = d.pop("results") for results_item_data in _results: results_item = Account.from_dict(results_item_data) results.append(results_item) def _parse_next_(data: object) -> Union[None, Unset, str]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, str], data) next_ = _parse_next_(d.pop("next", UNSET)) def _parse_previous(data: object) -> Union[None, Unset, str]: if data is None: return data if isinstance(data, Unset): return data return cast(Union[None, Unset, str], data) previous = _parse_previous(d.pop("previous", UNSET)) paginated_account_list = cls( count=count, results=results, next_=next_, previous=previous, ) paginated_account_list.additional_properties = d return paginated_account_list @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