# -*- coding: utf-8 -*-

"""
paypalserversdk

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
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):
        """Constructor for the BalanceInformation class"""

        # 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):
        """Creates 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 (f'{self.__class__.__name__}('
                f'currency={self.currency!r}, '
                f'primary={(self.primary if hasattr(self, "primary") else None)!r}, '
                f'total_balance={self.total_balance!r}, '
                f'available_balance={(self.available_balance if hasattr(self, "available_balance") else None)!r}, '
                f'withheld_balance={(self.withheld_balance if hasattr(self, "withheld_balance") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'currency={self.currency!s}, '
                f'primary={(self.primary if hasattr(self, "primary") else None)!s}, '
                f'total_balance={self.total_balance!s}, '
                f'available_balance={(self.available_balance if hasattr(self, "available_balance") else None)!s}, '
                f'withheld_balance={(self.withheld_balance if hasattr(self, "withheld_balance") else None)!s})')
