"""paypalserversdk.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from paypalserversdk.api_helper import APIHelper
from paypalserversdk.models.money import Money


class BalanceInformation(object):
    """Implementation of the 'Balance Information' model.

    The Balance information.

    Attributes:
        currency (str): The [three-character ISO-4217 currency
            code](/docs/integration/direct/rest/currency-codes/) that identifies the
            currency.
        primary (bool): Optional field representing if the currency is primary
            currency or not.
        total_balance (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        available_balance (Money): The currency and amount for a financial
            transaction, such as a balance or payment due.
        withheld_balance (Money): The currency and amount for a financial
            transaction, such as a balance or payment due.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "currency": "currency",
        "total_balance": "total_balance",
        "primary": "primary",
        "available_balance": "available_balance",
        "withheld_balance": "withheld_balance",
    }

    _optionals = [
        "primary",
        "available_balance",
        "withheld_balance",
    ]

    def __init__(
        self,
        currency=None,
        total_balance=None,
        primary=APIHelper.SKIP,
        available_balance=APIHelper.SKIP,
        withheld_balance=APIHelper.SKIP):
        """Initialize a BalanceInformation instance."""
        # Initialize members of the class
        self.currency = currency
        if primary is not APIHelper.SKIP:
            self.primary = primary
        self.total_balance = total_balance
        if available_balance is not APIHelper.SKIP:
            self.available_balance = available_balance
        if withheld_balance is not APIHelper.SKIP:
            self.withheld_balance = withheld_balance

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Create an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        currency =\
            dictionary.get("currency")\
            if dictionary.get("currency")\
                else None
        total_balance =\
            Money.from_dictionary(
                dictionary.get("total_balance"))\
                if dictionary.get("total_balance") else None
        primary =\
            dictionary.get("primary")\
            if "primary" in dictionary.keys()\
                else APIHelper.SKIP
        available_balance =\
            Money.from_dictionary(
                dictionary.get("available_balance"))\
                if "available_balance" in dictionary.keys()\
                else APIHelper.SKIP
        withheld_balance =\
            Money.from_dictionary(
                dictionary.get("withheld_balance"))\
                if "withheld_balance" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(currency,
                   total_balance,
                   primary,
                   available_balance,
                   withheld_balance)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _currency=self.currency
        _primary=(
            self.primary
            if hasattr(self, "primary")
            else None
        )
        _total_balance=self.total_balance
        _available_balance=(
            self.available_balance
            if hasattr(self, "available_balance")
            else None
        )
        _withheld_balance=(
            self.withheld_balance
            if hasattr(self, "withheld_balance")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"currency={_currency!r}, "
            f"primary={_primary!r}, "
            f"total_balance={_total_balance!r}, "
            f"available_balance={_available_balance!r}, "
            f"withheld_balance={_withheld_balance!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _currency=self.currency
        _primary=(
            self.primary
            if hasattr(self, "primary")
            else None
        )
        _total_balance=self.total_balance
        _available_balance=(
            self.available_balance
            if hasattr(self, "available_balance")
            else None
        )
        _withheld_balance=(
            self.withheld_balance
            if hasattr(self, "withheld_balance")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"currency={_currency!s}, "
            f"primary={_primary!s}, "
            f"total_balance={_total_balance!s}, "
            f"available_balance={_available_balance!s}, "
            f"withheld_balance={_withheld_balance!s}, "
            f")"
        )
