"""cellpointapi.

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

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.payment_transaction import (
    PaymentTransaction,
)


class AuthorizeOrderByIdPost201Response(object):
    """Implementation of the 'AuthorizeOrderById.POST.201.Response' model.

    Response containing the authorized payment transactions and all newly created
    transactions.

    Attributes:
        authorized_payment_transactions (List[PaymentTransaction]): A list of only
            the authorized payment transactions.  This field is now deprecated. All
            the payment transactions are contained in the `allCreatedTransactions`
            list, along with other types of transactions as well.
        all_created_transactions (List[PaymentTransaction | RefundTransaction |
            ExternalTransaction]): A list of newly created transactions. They may
            include payment and external transactions.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "authorized_payment_transactions": "authorizedPaymentTransactions",
        "all_created_transactions": "allCreatedTransactions",
    }

    def __init__(
        self,
        authorized_payment_transactions=None,
        all_created_transactions=None,
        additional_properties=None):
        """Initialize a AuthorizeOrderByIdPost201Response instance."""
        # Initialize members of the class
        self.authorized_payment_transactions = authorized_payment_transactions
        self.all_created_transactions = all_created_transactions

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @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.

        """
        from cellpointapi.utilities.union_type_lookup import (
            UnionTypeLookUp,
        )

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

        # Extract variables from the dictionary
        authorized_payment_transactions = None
        if dictionary.get("authorizedPaymentTransactions") is not None:
            authorized_payment_transactions = [
                PaymentTransaction.from_dictionary(x)
                    for x in dictionary.get("authorizedPaymentTransactions")
            ]
        all_created_transactions = APIHelper.deserialize_union_type(
            UnionTypeLookUp.get("Transaction2"),
            dictionary.get("allCreatedTransactions"),
            False)\
            if dictionary.get("allCreatedTransactions") is not None\
            else None

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(authorized_payment_transactions,
                   all_created_transactions,
                   additional_properties)

    @classmethod
    def validate(cls, dictionary):
        """Validate dictionary against class required properties

        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:
            boolean : if dictionary is valid contains required properties.

        """
        from cellpointapi.utilities.union_type_lookup import (
            UnionTypeLookUp,
        )

        if isinstance(dictionary, cls):
            return APIHelper.is_valid_type(
                    value=dictionary.authorized_payment_transactions,
                    type_callable=lambda value:
                        PaymentTransaction.validate(value),
                    is_model_dict=True,
                    is_inner_model_dict=True) \
                and (UnionTypeLookUp.get("Transaction2")
                .validate(dictionary.all_created_transactions).is_valid)

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("authorizedPaymentTransactions"),
                type_callable=lambda value:
                    PaymentTransaction.validate(value),
                is_model_dict=True,
                is_inner_model_dict=True) \
            and (UnionTypeLookUp.get("Transaction2")
            .validate(dictionary.get("allCreatedTransactions")).is_valid)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _authorized_payment_transactions=self.authorized_payment_transactions
        _all_created_transactions=self.all_created_transactions
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"authorized_payment_transactions={_authorized_payment_transactions!r}, "
            f"all_created_transactions={_all_created_transactions!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _authorized_payment_transactions=self.authorized_payment_transactions
        _all_created_transactions=self.all_created_transactions
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"authorized_payment_transactions={_authorized_payment_transactions!s}, "
            f"all_created_transactions={_all_created_transactions!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
