# -*- 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.order_update_callback_shipping_address import OrderUpdateCallbackShippingAddress
from paypalserversdk.models.order_update_callback_shipping_option import OrderUpdateCallbackShippingOption
from paypalserversdk.models.purchase_unit_request import PurchaseUnitRequest


class OrderUpdateCallbackRequest(object):

    """Implementation of the 'Order Update Callback Request' model.

    Shipping Options Callback request. This will be implemented by the
    merchants.

    Attributes:
        id (str): The ID of the order.
        shipping_address (OrderUpdateCallbackShippingAddress): The portable
            international postal address. Maps to
            [AddressValidationMetadata](https://github.com/googlei18n/libaddres
            sinput/wiki/AddressValidationMetadata) and HTML 5.1 [Autofilling
            form controls: the autocomplete
            attribute](https://www.w3.org/TR/html51/sec-forms.html#autofilling-
            form-controls-the-autocomplete-attribute).
        shipping_option (OrderUpdateCallbackShippingOption): The options that
            the payee or merchant offers to the payer to ship or pick up their
            items.
        purchase_units (List[PurchaseUnitRequest]): An array of purchase
            units. At present only 1 purchase_unit is supported. 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.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "shipping_address": 'shipping_address',
        "purchase_units": 'purchase_units',
        "id": 'id',
        "shipping_option": 'shipping_option'
    }

    _optionals = [
        'id',
        'shipping_option',
    ]

    def __init__(self,
                 shipping_address=None,
                 purchase_units=None,
                 id=APIHelper.SKIP,
                 shipping_option=APIHelper.SKIP):
        """Constructor for the OrderUpdateCallbackRequest class"""

        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id 
        self.shipping_address = shipping_address 
        if shipping_option is not APIHelper.SKIP:
            self.shipping_option = shipping_option 
        self.purchase_units = purchase_units 

    @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
        shipping_address = OrderUpdateCallbackShippingAddress.from_dictionary(dictionary.get('shipping_address')) if dictionary.get('shipping_address') 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')]
        id = dictionary.get("id") if dictionary.get("id") else APIHelper.SKIP
        shipping_option = OrderUpdateCallbackShippingOption.from_dictionary(dictionary.get('shipping_option')) if 'shipping_option' in dictionary.keys() else APIHelper.SKIP
        # Return an object of this model
        return cls(shipping_address,
                   purchase_units,
                   id,
                   shipping_option)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'id={(self.id if hasattr(self, "id") else None)!r}, '
                f'shipping_address={self.shipping_address!r}, '
                f'shipping_option={(self.shipping_option if hasattr(self, "shipping_option") else None)!r}, '
                f'purchase_units={self.purchase_units!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'id={(self.id if hasattr(self, "id") else None)!s}, '
                f'shipping_address={self.shipping_address!s}, '
                f'shipping_option={(self.shipping_option if hasattr(self, "shipping_option") else None)!s}, '
                f'purchase_units={self.purchase_units!s})')
