# coding: utf-8

"""
    Bluefin API

    Bluefin API

    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from bluefin_pro_api_client.models.asset2 import Asset2
from bluefin_pro_api_client.models.fee_tier import FeeTier
from typing import Optional, Set
from typing_extensions import Self

class AccountUpdate(BaseModel):
    """
    Account information for the data stream.
    """ # noqa: E501
    fee_tier: Optional[FeeTier] = Field(default=None, alias="feeTier")
    can_trade: StrictBool = Field(description="Indicates if trading is enabled.", alias="canTrade")
    can_deposit: StrictBool = Field(description="Indicates if deposits are enabled.", alias="canDeposit")
    can_withdraw: StrictBool = Field(description="Indicates if withdrawals are enabled.", alias="canWithdraw")
    total_effective_balance_e9: StrictStr = Field(description="The total effective balance.", alias="totalEffectiveBalanceE9")
    total_initial_margin_required_e9: StrictStr = Field(description="The total initial margin required.", alias="totalInitialMarginRequiredE9")
    total_open_order_initial_margin_required_e9: StrictStr = Field(description="The initial margin required for open orders.", alias="totalOpenOrderInitialMarginRequiredE9")
    initial_margin_available_e9: StrictStr = Field(description="The available initial margin.", alias="initialMarginAvailableE9")
    total_maintenance_margin_required_e9: StrictStr = Field(description="The total maintenance margin required.", alias="totalMaintenanceMarginRequiredE9")
    maintenance_margin_available_e9: StrictStr = Field(description="The available maintenance margin.", alias="maintenanceMarginAvailableE9")
    account_maintenance_margin_ratio_e9: StrictStr = Field(description="The maintenance margin ratio.", alias="accountMaintenanceMarginRatioE9")
    account_leverage_e9: StrictStr = Field(description="The account leverage.", alias="accountLeverageE9")
    total_unrealized_pnl_e9: StrictStr = Field(description="The total unrealized profit and loss.", alias="totalUnrealizedPnlE9")
    total_cross_unrealized_pnl_e9: StrictStr = Field(description="The total cross unrealized profit and loss.", alias="totalCrossUnrealizedPnlE9")
    updated_at_utc_millis: StrictInt = Field(description="The timestamp of the last update in milliseconds.", alias="updatedAtUtcMillis")
    assets: List[Asset2] = Field(description="The list of assets.")
    __properties: ClassVar[List[str]] = ["feeTier", "canTrade", "canDeposit", "canWithdraw", "totalEffectiveBalanceE9", "totalInitialMarginRequiredE9", "totalOpenOrderInitialMarginRequiredE9", "initialMarginAvailableE9", "totalMaintenanceMarginRequiredE9", "maintenanceMarginAvailableE9", "accountMaintenanceMarginRatioE9", "accountLeverageE9", "totalUnrealizedPnlE9", "totalCrossUnrealizedPnlE9", "updatedAtUtcMillis", "assets"]

    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 AccountUpdate 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 fee_tier
        if self.fee_tier:
            _dict['feeTier'] = self.fee_tier.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in assets (list)
        _items = []
        if self.assets:
            for _item_assets in self.assets:
                if _item_assets:
                    _items.append(_item_assets.to_dict())
            _dict['assets'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "feeTier": FeeTier.from_dict(obj["feeTier"]) if obj.get("feeTier") is not None else None,
            "canTrade": obj.get("canTrade"),
            "canDeposit": obj.get("canDeposit"),
            "canWithdraw": obj.get("canWithdraw"),
            "totalEffectiveBalanceE9": obj.get("totalEffectiveBalanceE9"),
            "totalInitialMarginRequiredE9": obj.get("totalInitialMarginRequiredE9"),
            "totalOpenOrderInitialMarginRequiredE9": obj.get("totalOpenOrderInitialMarginRequiredE9"),
            "initialMarginAvailableE9": obj.get("initialMarginAvailableE9"),
            "totalMaintenanceMarginRequiredE9": obj.get("totalMaintenanceMarginRequiredE9"),
            "maintenanceMarginAvailableE9": obj.get("maintenanceMarginAvailableE9"),
            "accountMaintenanceMarginRatioE9": obj.get("accountMaintenanceMarginRatioE9"),
            "accountLeverageE9": obj.get("accountLeverageE9"),
            "totalUnrealizedPnlE9": obj.get("totalUnrealizedPnlE9"),
            "totalCrossUnrealizedPnlE9": obj.get("totalCrossUnrealizedPnlE9"),
            "updatedAtUtcMillis": obj.get("updatedAtUtcMillis"),
            "assets": [Asset2.from_dict(_item) for _item in obj["assets"]] if obj.get("assets") is not None else None
        })
        return _obj


