"""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.order_application_context import (
    OrderApplicationContext,
)
from paypalserversdk.models.payer import Payer
from paypalserversdk.models.payment_source import (
    PaymentSource,
)
from paypalserversdk.models.purchase_unit_request import (
    PurchaseUnitRequest,
)


class OrderRequest(object):
    """Implementation of the 'Order Request' model.

    The order request details.

    Attributes:
        intent (CheckoutPaymentIntent): The intent to either capture payment
            immediately or authorize a payment for an order after order creation.
        payer (Payer): DEPRECATED. The customer is also known as the payer. The Payer
            object was intended to only be used with the `payment_source.paypal`
            object. In order to make this design more clear, the details in the
            `payer` object are now available under `payment_source.paypal`. Please
            use `payment_source.paypal`.
        purchase_units (List[PurchaseUnitRequest]): An array of purchase units. Each
            purchase unit establishes a contract between a payer and the payee. Each
            purchase unit represents either a full or partial order that the payer
            intends to purchase from the payee.
        payment_source (PaymentSource): The payment source definition.
        application_context (OrderApplicationContext): Customizes the payer
            experience during the approval process for the payment with PayPal. Note:
            Partners and Marketplaces might configure brand_name and
            shipping_preference during partner account setup, which overrides the
            request values.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "intent": "intent",
        "purchase_units": "purchase_units",
        "payer": "payer",
        "payment_source": "payment_source",
        "application_context": "application_context",
    }

    _optionals = [
        "payer",
        "payment_source",
        "application_context",
    ]

    def __init__(
        self,
        intent=None,
        purchase_units=None,
        payer=APIHelper.SKIP,
        payment_source=APIHelper.SKIP,
        application_context=APIHelper.SKIP):
        """Initialize a OrderRequest instance."""
        # Initialize members of the class
        self.intent = intent
        if payer is not APIHelper.SKIP:
            self.payer = payer
        self.purchase_units = purchase_units
        if payment_source is not APIHelper.SKIP:
            self.payment_source = payment_source
        if application_context is not APIHelper.SKIP:
            self.application_context = application_context

    @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
        intent =\
            dictionary.get("intent")\
            if dictionary.get("intent")\
                else None
        purchase_units = None
        if dictionary.get("purchase_units") is not None:
            purchase_units = [
                PurchaseUnitRequest.from_dictionary(x)
                    for x in dictionary.get("purchase_units")
            ]
        payer =\
            Payer.from_dictionary(
                dictionary.get("payer"))\
                if "payer" in dictionary.keys()\
                else APIHelper.SKIP
        payment_source =\
            PaymentSource.from_dictionary(
                dictionary.get("payment_source"))\
                if "payment_source" in dictionary.keys()\
                else APIHelper.SKIP
        application_context =\
            OrderApplicationContext.from_dictionary(
                dictionary.get("application_context"))\
                if "application_context" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(intent,
                   purchase_units,
                   payer,
                   payment_source,
                   application_context)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _intent=self.intent
        _payer=(
            self.payer
            if hasattr(self, "payer")
            else None
        )
        _purchase_units=self.purchase_units
        _payment_source=(
            self.payment_source
            if hasattr(self, "payment_source")
            else None
        )
        _application_context=(
            self.application_context
            if hasattr(self, "application_context")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"intent={_intent!r}, "
            f"payer={_payer!r}, "
            f"purchase_units={_purchase_units!r}, "
            f"payment_source={_payment_source!r}, "
            f"application_context={_application_context!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _intent=self.intent
        _payer=(
            self.payer
            if hasattr(self, "payer")
            else None
        )
        _purchase_units=self.purchase_units
        _payment_source=(
            self.payment_source
            if hasattr(self, "payment_source")
            else None
        )
        _application_context=(
            self.application_context
            if hasattr(self, "application_context")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"intent={_intent!s}, "
            f"payer={_payer!s}, "
            f"purchase_units={_purchase_units!s}, "
            f"payment_source={_payment_source!s}, "
            f"application_context={_application_context!s}, "
            f")"
        )
