# -*- 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.amount_with_breakdown import AmountWithBreakdown
from paypalserversdk.models.item import Item
from paypalserversdk.models.shipping_option import ShippingOption


class ShippingOptionsPurchaseUnit(object):

    """Implementation of the 'Shipping Options Purchase Unit' model.

    This would contain shipping option and amount data at purchase unit level.

    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.
        items (List[Item]): An array of items that the customer purchases from
            the merchant.
        shipping_options (List[ShippingOption]): An array of shipping options
            that the payee or merchant offers to the payer to ship or pick up
            their items.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "reference_id": 'reference_id',
        "amount": 'amount',
        "items": 'items',
        "shipping_options": 'shipping_options'
    }

    _optionals = [
        'reference_id',
        'amount',
        'items',
        'shipping_options',
    ]

    def __init__(self,
                 reference_id=APIHelper.SKIP,
                 amount=APIHelper.SKIP,
                 items=APIHelper.SKIP,
                 shipping_options=APIHelper.SKIP):
        """Constructor for the ShippingOptionsPurchaseUnit class"""

        # 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 items is not APIHelper.SKIP:
            self.items = items 
        if shipping_options is not APIHelper.SKIP:
            self.shipping_options = shipping_options 

    @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
        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
        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_options = None
        if dictionary.get('shipping_options') is not None:
            shipping_options = [ShippingOption.from_dictionary(x) for x in dictionary.get('shipping_options')]
        else:
            shipping_options = APIHelper.SKIP
        # Return an object of this model
        return cls(reference_id,
                   amount,
                   items,
                   shipping_options)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'reference_id={(self.reference_id if hasattr(self, "reference_id") else None)!r}, '
                f'amount={(self.amount if hasattr(self, "amount") else None)!r}, '
                f'items={(self.items if hasattr(self, "items") else None)!r}, '
                f'shipping_options={(self.shipping_options if hasattr(self, "shipping_options") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'reference_id={(self.reference_id if hasattr(self, "reference_id") else None)!s}, '
                f'amount={(self.amount if hasattr(self, "amount") else None)!s}, '
                f'items={(self.items if hasattr(self, "items") else None)!s}, '
                f'shipping_options={(self.shipping_options if hasattr(self, "shipping_options") else None)!s})')
