"""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.amount_with_breakdown import (
    AmountWithBreakdown,
)
from paypalserversdk.models.item import Item
from paypalserversdk.models.payee_base import (
    PayeeBase,
)
from paypalserversdk.models.payment_collection import (
    PaymentCollection,
)
from paypalserversdk.models.payment_instruction import (
    PaymentInstruction,
)
from paypalserversdk.models.shipping_with_tracking_details import (
    ShippingWithTrackingDetails,
)
from paypalserversdk.models.supplementary_data import (
    SupplementaryData,
)


class PurchaseUnit(object):
    """Implementation of the 'Purchase Unit' model.

    The purchase unit details. Used to capture required information for the payment
    contract.

    Attributes:
        reference_id (str): The API caller-provided external ID for the purchase
            unit. Required for multiple purchase units when you must update the order
            through `PATCH`. If you omit this value and the order contains only one
            purchase unit, PayPal sets this value to `default`. Note: If there are
            multiple purchase units, reference_id is required for each purchase unit.
        amount (AmountWithBreakdown): The total order amount with an optional
            breakdown that provides details, such as the total item amount, total tax
            amount, shipping, handling, insurance, and discounts, if any. If you
            specify `amount.breakdown`, the amount equals `item_total` plus
            `tax_total` plus `shipping` plus `handling` plus `insurance` minus
            `shipping_discount` minus discount. The amount must be a positive number.
            For listed of supported currencies and decimal precision, see the PayPal
            REST APIs Currency Codes.
        payee (PayeeBase): The merchant who receives the funds and fulfills the
            order. The merchant is also known as the payee.
        payment_instruction (PaymentInstruction): Any additional payment instructions
            to be consider during payment processing. This processing instruction is
            applicable for Capturing an order or Authorizing an Order.
        description (str): The purchase description.
        custom_id (str): The API caller-provided external ID. Used to reconcile API
            caller-initiated transactions with PayPal transactions. Appears in
            transaction and settlement reports.
        invoice_id (str): The API caller-provided external invoice ID for this order.
        id (str): The PayPal-generated ID for the purchase unit. This ID appears in
            both the payer's transaction history and the emails that the payer
            receives. In addition, this ID is available in transaction and settlement
            reports that merchants and API callers can use to reconcile transactions.
            This ID is only available when an order is saved by calling
            v2/checkout/orders/id/save.
        soft_descriptor (str): The payment descriptor on account transactions on the
            customer's credit card statement, that PayPal sends to processors. The
            maximum length of the soft descriptor information that you can pass in
            the API field is 22 characters, in the following format:22 - len(PAYPAL *
            (8)) - len(Descriptor in Payment Receiving Preferences of Merchant
            account + 1)The PAYPAL prefix uses 8 characters. The soft descriptor
            supports the following ASCII characters: Alphanumeric characters Dashes
            Asterisks Periods (.) Spaces For Wallet payments marketplace
            integrations: The merchant descriptor in the Payment Receiving
            Preferences must be the marketplace name. You can't use the remaining
            space to show the customer service number. The remaining spaces can be a
            combination of seller name and country. For unbranded payments (Direct
            Card) marketplace integrations, use a combination of the seller name and
            phone number.
        items (List[Item]): An array of items that the customer purchases from the
            merchant.
        shipping (ShippingWithTrackingDetails): The order shipping details.
        supplementary_data (SupplementaryData): Supplementary data about a payment.
            This object passes information that can be used to improve risk
            assessments and processing costs, for example, by providing Level 2 and
            Level 3 payment data.
        payments (PaymentCollection): The collection of payments, or transactions,
            for a purchase unit in an order. For example, authorized payments,
            captured payments, and refunds.
        most_recent_errors (List[Any]): The error reason code and description that
            are the reason for the most recent order decline.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "reference_id": "reference_id",
        "amount": "amount",
        "payee": "payee",
        "payment_instruction": "payment_instruction",
        "description": "description",
        "custom_id": "custom_id",
        "invoice_id": "invoice_id",
        "id": "id",
        "soft_descriptor": "soft_descriptor",
        "items": "items",
        "shipping": "shipping",
        "supplementary_data": "supplementary_data",
        "payments": "payments",
        "most_recent_errors": "most_recent_errors",
    }

    _optionals = [
        "reference_id",
        "amount",
        "payee",
        "payment_instruction",
        "description",
        "custom_id",
        "invoice_id",
        "id",
        "soft_descriptor",
        "items",
        "shipping",
        "supplementary_data",
        "payments",
        "most_recent_errors",
    ]

    def __init__(
        self,
        reference_id=APIHelper.SKIP,
        amount=APIHelper.SKIP,
        payee=APIHelper.SKIP,
        payment_instruction=APIHelper.SKIP,
        description=APIHelper.SKIP,
        custom_id=APIHelper.SKIP,
        invoice_id=APIHelper.SKIP,
        id=APIHelper.SKIP,
        soft_descriptor=APIHelper.SKIP,
        items=APIHelper.SKIP,
        shipping=APIHelper.SKIP,
        supplementary_data=APIHelper.SKIP,
        payments=APIHelper.SKIP,
        most_recent_errors=APIHelper.SKIP):
        """Initialize a PurchaseUnit instance."""
        # Initialize members of the class
        if reference_id is not APIHelper.SKIP:
            self.reference_id = reference_id
        if amount is not APIHelper.SKIP:
            self.amount = amount
        if payee is not APIHelper.SKIP:
            self.payee = payee
        if payment_instruction is not APIHelper.SKIP:
            self.payment_instruction = payment_instruction
        if description is not APIHelper.SKIP:
            self.description = description
        if custom_id is not APIHelper.SKIP:
            self.custom_id = custom_id
        if invoice_id is not APIHelper.SKIP:
            self.invoice_id = invoice_id
        if id is not APIHelper.SKIP:
            self.id = id
        if soft_descriptor is not APIHelper.SKIP:
            self.soft_descriptor = soft_descriptor
        if items is not APIHelper.SKIP:
            self.items = items
        if shipping is not APIHelper.SKIP:
            self.shipping = shipping
        if supplementary_data is not APIHelper.SKIP:
            self.supplementary_data = supplementary_data
        if payments is not APIHelper.SKIP:
            self.payments = payments
        if most_recent_errors is not APIHelper.SKIP:
            self.most_recent_errors = most_recent_errors

    @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
        reference_id =\
            dictionary.get("reference_id")\
            if dictionary.get("reference_id")\
                else APIHelper.SKIP
        amount =\
            AmountWithBreakdown.from_dictionary(
                dictionary.get("amount"))\
                if "amount" in dictionary.keys()\
                else APIHelper.SKIP
        payee =\
            PayeeBase.from_dictionary(
                dictionary.get("payee"))\
                if "payee" in dictionary.keys()\
                else APIHelper.SKIP
        payment_instruction =\
            PaymentInstruction.from_dictionary(
                dictionary.get("payment_instruction"))\
                if "payment_instruction" in dictionary.keys()\
                else APIHelper.SKIP
        description =\
            dictionary.get("description")\
            if dictionary.get("description")\
                else APIHelper.SKIP
        custom_id =\
            dictionary.get("custom_id")\
            if dictionary.get("custom_id")\
                else APIHelper.SKIP
        invoice_id =\
            dictionary.get("invoice_id")\
            if dictionary.get("invoice_id")\
                else APIHelper.SKIP
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else APIHelper.SKIP
        soft_descriptor =\
            dictionary.get("soft_descriptor")\
            if dictionary.get("soft_descriptor")\
                else APIHelper.SKIP
        items = None
        if dictionary.get("items") is not None:
            items = [
                Item.from_dictionary(x)
                    for x in dictionary.get("items")
            ]
        else:
            items = APIHelper.SKIP
        shipping =\
            ShippingWithTrackingDetails.from_dictionary(
                dictionary.get("shipping"))\
                if "shipping" in dictionary.keys()\
                else APIHelper.SKIP
        supplementary_data =\
            SupplementaryData.from_dictionary(
                dictionary.get("supplementary_data"))\
                if "supplementary_data" in dictionary.keys()\
                else APIHelper.SKIP
        payments =\
            PaymentCollection.from_dictionary(
                dictionary.get("payments"))\
                if "payments" in dictionary.keys()\
                else APIHelper.SKIP
        most_recent_errors =\
            dictionary.get("most_recent_errors")\
            if dictionary.get("most_recent_errors")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(reference_id,
                   amount,
                   payee,
                   payment_instruction,
                   description,
                   custom_id,
                   invoice_id,
                   id,
                   soft_descriptor,
                   items,
                   shipping,
                   supplementary_data,
                   payments,
                   most_recent_errors)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _reference_id=(
            self.reference_id
            if hasattr(self, "reference_id")
            else None
        )
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _payee=(
            self.payee
            if hasattr(self, "payee")
            else None
        )
        _payment_instruction=(
            self.payment_instruction
            if hasattr(self, "payment_instruction")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _custom_id=(
            self.custom_id
            if hasattr(self, "custom_id")
            else None
        )
        _invoice_id=(
            self.invoice_id
            if hasattr(self, "invoice_id")
            else None
        )
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _soft_descriptor=(
            self.soft_descriptor
            if hasattr(self, "soft_descriptor")
            else None
        )
        _items=(
            self.items
            if hasattr(self, "items")
            else None
        )
        _shipping=(
            self.shipping
            if hasattr(self, "shipping")
            else None
        )
        _supplementary_data=(
            self.supplementary_data
            if hasattr(self, "supplementary_data")
            else None
        )
        _payments=(
            self.payments
            if hasattr(self, "payments")
            else None
        )
        _most_recent_errors=(
            self.most_recent_errors
            if hasattr(self, "most_recent_errors")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"reference_id={_reference_id!r}, "
            f"amount={_amount!r}, "
            f"payee={_payee!r}, "
            f"payment_instruction={_payment_instruction!r}, "
            f"description={_description!r}, "
            f"custom_id={_custom_id!r}, "
            f"invoice_id={_invoice_id!r}, "
            f"id={_id!r}, "
            f"soft_descriptor={_soft_descriptor!r}, "
            f"items={_items!r}, "
            f"shipping={_shipping!r}, "
            f"supplementary_data={_supplementary_data!r}, "
            f"payments={_payments!r}, "
            f"most_recent_errors={_most_recent_errors!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _reference_id=(
            self.reference_id
            if hasattr(self, "reference_id")
            else None
        )
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _payee=(
            self.payee
            if hasattr(self, "payee")
            else None
        )
        _payment_instruction=(
            self.payment_instruction
            if hasattr(self, "payment_instruction")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _custom_id=(
            self.custom_id
            if hasattr(self, "custom_id")
            else None
        )
        _invoice_id=(
            self.invoice_id
            if hasattr(self, "invoice_id")
            else None
        )
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _soft_descriptor=(
            self.soft_descriptor
            if hasattr(self, "soft_descriptor")
            else None
        )
        _items=(
            self.items
            if hasattr(self, "items")
            else None
        )
        _shipping=(
            self.shipping
            if hasattr(self, "shipping")
            else None
        )
        _supplementary_data=(
            self.supplementary_data
            if hasattr(self, "supplementary_data")
            else None
        )
        _payments=(
            self.payments
            if hasattr(self, "payments")
            else None
        )
        _most_recent_errors=(
            self.most_recent_errors
            if hasattr(self, "most_recent_errors")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"reference_id={_reference_id!s}, "
            f"amount={_amount!s}, "
            f"payee={_payee!s}, "
            f"payment_instruction={_payment_instruction!s}, "
            f"description={_description!s}, "
            f"custom_id={_custom_id!s}, "
            f"invoice_id={_invoice_id!s}, "
            f"id={_id!s}, "
            f"soft_descriptor={_soft_descriptor!s}, "
            f"items={_items!s}, "
            f"shipping={_shipping!s}, "
            f"supplementary_data={_supplementary_data!s}, "
            f"payments={_payments!s}, "
            f"most_recent_errors={_most_recent_errors!s}, "
            f")"
        )
