"""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_request import (
    ItemRequest,
)
from paypalserversdk.models.payee_base import (
    PayeeBase,
)
from paypalserversdk.models.payment_instruction import (
    PaymentInstruction,
)
from paypalserversdk.models.shipping_details import (
    ShippingDetails,
)
from paypalserversdk.models.supplementary_data import (
    SupplementaryData,
)


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

    The purchase unit request. Includes 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`.
        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): This field supports up to 3,000 characters, but any
            content beyond 127 characters (including spaces) will be truncated. The
            127 character limit is reflected in the response representation of this
            field. The purchase description. The maximum length of the character is
            dependent on the type of characters used. The character length is
            specified assuming a US ASCII character. Depending on type of character;
            (e.g. accented character, Japanese characters) the number of characters
            that that can be specified as input might not equal the permissible max
            length.
        custom_id (str): The API caller-provided external ID. Used to reconcile
            client transactions with PayPal transactions. Appears in transaction and
            settlement reports but is not visible to the payer.
        invoice_id (str): The API caller-provided external invoice number for this
            order. Appears in both the payer's transaction history and the emails
            that the payer receives. invoice_id values are required to be unique
            within each merchant account by default. Although the uniqueness
            validation is configurable, disabling this behavior will remove the
            account's ability to use invoice_id in other APIs as an identifier. It is
            highly recommended to keep a unique invoice_id for each Order.
        soft_descriptor (str): This field supports up to 127 characters, but any
            content beyond 22 characters (including spaces) will be truncated. The 22
            character limit is reflected in the response representation of this
            field. The soft descriptor is the dynamic text used to construct the
            statement descriptor that appears on a payer's card statement. If an
            Order is paid using the "PayPal Wallet", the statement descriptor will
            appear in following format on the payer's card statement:
            PAYPAL_prefix+(space)+merchant_descriptor+(space)+ soft_descriptor Note:
            The merchant descriptor is the descriptor of the merchant’s payment
            receiving preferences which can be seen by logging into the merchant
            account https://www.sandbox.paypal.com/businessprofile/settings/info/edit
            The PAYPAL prefix uses 8 characters. Only the first 22 characters will be
            displayed in the statement. For example, if: The PayPal prefix toggle is
            PAYPAL *. The merchant descriptor in the profile is Janes Gift. The soft
            descriptor is 800-123-1234. Then, the statement descriptor on the card is
            PAYPAL * Janes Gift 80.
        items (List[ItemRequest]): An array of items that the customer purchases from
            the merchant.
        shipping (ShippingDetails): The 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.

    """

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

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

    def __init__(
        self,
        amount=None,
        reference_id=APIHelper.SKIP,
        payee=APIHelper.SKIP,
        payment_instruction=APIHelper.SKIP,
        description=APIHelper.SKIP,
        custom_id=APIHelper.SKIP,
        invoice_id=APIHelper.SKIP,
        soft_descriptor=APIHelper.SKIP,
        items=APIHelper.SKIP,
        shipping=APIHelper.SKIP,
        supplementary_data=APIHelper.SKIP):
        """Initialize a PurchaseUnitRequest instance."""
        # Initialize members of the class
        if reference_id is not APIHelper.SKIP:
            self.reference_id = reference_id
        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 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

    @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
        amount =\
            AmountWithBreakdown.from_dictionary(
                dictionary.get("amount"))\
                if dictionary.get("amount") else None
        reference_id =\
            dictionary.get("reference_id")\
            if dictionary.get("reference_id")\
                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
        soft_descriptor =\
            dictionary.get("soft_descriptor")\
            if dictionary.get("soft_descriptor")\
                else APIHelper.SKIP
        items = None
        if dictionary.get("items") is not None:
            items = [
                ItemRequest.from_dictionary(x)
                    for x in dictionary.get("items")
            ]
        else:
            items = APIHelper.SKIP
        shipping =\
            ShippingDetails.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

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

    def __repr__(self):
        """Return a unambiguous string representation."""
        _reference_id=(
            self.reference_id
            if hasattr(self, "reference_id")
            else None
        )
        _amount=self.amount
        _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
        )
        _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
        )
        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"soft_descriptor={_soft_descriptor!r}, "
            f"items={_items!r}, "
            f"shipping={_shipping!r}, "
            f"supplementary_data={_supplementary_data!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
        _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
        )
        _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
        )
        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"soft_descriptor={_soft_descriptor!s}, "
            f"items={_items!s}, "
            f"shipping={_shipping!s}, "
            f"supplementary_data={_supplementary_data!s}, "
            f")"
        )
