# coding: utf-8

"""
Crypticorn Auth API

OpenAPI compliant REST API built using tRPC with Express

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from crypticorn.auth.client.models.list_wallets200_response_balances_inner_wallet_vesting_wallets_inner import (
    ListWallets200ResponseBalancesInnerWalletVestingWalletsInner,
)
from typing import Optional, Set
from typing_extensions import Self


class ListWallets200ResponseBalancesInnerWallet(BaseModel):
    """
    ListWallets200ResponseBalancesInnerWallet
    """  # noqa: E501

    id: Optional[Any] = Field(default=None, alias="_id")
    v: Optional[Any] = Field(default=None, alias="__v")
    created_at: Optional[StrictStr] = Field(default=None, alias="createdAt")
    updated_at: Optional[StrictStr] = Field(default=None, alias="updatedAt")
    address: Optional[StrictStr] = None
    value_aic: Optional[Union[StrictFloat, StrictInt]] = Field(
        default=None, alias="valueAic"
    )
    expires_at: Optional[StrictStr] = Field(default=None, alias="expiresAt")
    vesting_wallets: List[
        ListWallets200ResponseBalancesInnerWalletVestingWalletsInner
    ] = Field(alias="vestingWallets")
    __properties: ClassVar[List[str]] = [
        "_id",
        "__v",
        "createdAt",
        "updatedAt",
        "address",
        "valueAic",
        "expiresAt",
        "vestingWallets",
    ]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ListWallets200ResponseBalancesInnerWallet from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in vesting_wallets (list)
        _items = []
        if self.vesting_wallets:
            for _item_vesting_wallets in self.vesting_wallets:
                if _item_vesting_wallets:
                    _items.append(_item_vesting_wallets.to_dict())
            _dict["vestingWallets"] = _items
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict["_id"] = None

        # set to None if v (nullable) is None
        # and model_fields_set contains the field
        if self.v is None and "v" in self.model_fields_set:
            _dict["__v"] = None

        # set to None if created_at (nullable) is None
        # and model_fields_set contains the field
        if self.created_at is None and "created_at" in self.model_fields_set:
            _dict["createdAt"] = None

        # set to None if updated_at (nullable) is None
        # and model_fields_set contains the field
        if self.updated_at is None and "updated_at" in self.model_fields_set:
            _dict["updatedAt"] = None

        # set to None if address (nullable) is None
        # and model_fields_set contains the field
        if self.address is None and "address" in self.model_fields_set:
            _dict["address"] = None

        # set to None if value_aic (nullable) is None
        # and model_fields_set contains the field
        if self.value_aic is None and "value_aic" in self.model_fields_set:
            _dict["valueAic"] = None

        # set to None if expires_at (nullable) is None
        # and model_fields_set contains the field
        if self.expires_at is None and "expires_at" in self.model_fields_set:
            _dict["expiresAt"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ListWallets200ResponseBalancesInnerWallet from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate(
            {
                "_id": obj.get("_id"),
                "__v": obj.get("__v"),
                "createdAt": obj.get("createdAt"),
                "updatedAt": obj.get("updatedAt"),
                "address": obj.get("address"),
                "valueAic": obj.get("valueAic"),
                "expiresAt": obj.get("expiresAt"),
                "vestingWallets": (
                    [
                        ListWallets200ResponseBalancesInnerWalletVestingWalletsInner.from_dict(
                            _item
                        )
                        for _item in obj["vestingWallets"]
                    ]
                    if obj.get("vestingWallets") is not None
                    else None
                ),
            }
        )
        return _obj
