# -*- coding: utf-8 -*-

"""
paypalrestapis

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
from paypalrestapis.api_helper import APIHelper
from paypalrestapis.models.address import Address
from paypalrestapis.models.shipping_name import ShippingName
from paypalrestapis.models.shipping_option import ShippingOption


class ShippingDetails(object):

    """Implementation of the 'Shipping Details' model.

    The shipping details.

    Attributes:
        name (ShippingName): The name of the party.
        mtype (FullfillmentType): A classification for the method of purchase
            fulfillment (e.g shipping, in-store pickup, etc). Either `type` or
            `options` may be present, but not both.
        options (List[ShippingOption]): An array of shipping options that the
            payee or merchant offers to the payer to ship or pick up their
            items.
        address (Address): 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).

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "name": 'name',
        "mtype": 'type',
        "options": 'options',
        "address": 'address'
    }

    _optionals = [
        'name',
        'mtype',
        'options',
        'address',
    ]

    def __init__(self,
                 name=APIHelper.SKIP,
                 mtype=APIHelper.SKIP,
                 options=APIHelper.SKIP,
                 address=APIHelper.SKIP):
        """Constructor for the ShippingDetails class"""

        # Initialize members of the class
        if name is not APIHelper.SKIP:
            self.name = name 
        if mtype is not APIHelper.SKIP:
            self.mtype = mtype 
        if options is not APIHelper.SKIP:
            self.options = options 
        if address is not APIHelper.SKIP:
            self.address = address 

    @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
        name = ShippingName.from_dictionary(dictionary.get('name')) if 'name' in dictionary.keys() else APIHelper.SKIP
        mtype = dictionary.get("type") if dictionary.get("type") else APIHelper.SKIP
        options = None
        if dictionary.get('options') is not None:
            options = [ShippingOption.from_dictionary(x) for x in dictionary.get('options')]
        else:
            options = APIHelper.SKIP
        address = Address.from_dictionary(dictionary.get('address')) if 'address' in dictionary.keys() else APIHelper.SKIP
        # Return an object of this model
        return cls(name,
                   mtype,
                   options,
                   address)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'name={(self.name if hasattr(self, "name") else None)!r}, '
                f'mtype={(self.mtype if hasattr(self, "mtype") else None)!r}, '
                f'options={(self.options if hasattr(self, "options") else None)!r}, '
                f'address={(self.address if hasattr(self, "address") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'name={(self.name if hasattr(self, "name") else None)!s}, '
                f'mtype={(self.mtype if hasattr(self, "mtype") else None)!s}, '
                f'options={(self.options if hasattr(self, "options") else None)!s}, '
                f'address={(self.address if hasattr(self, "address") else None)!s})')
