"""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.simple_postal_address_coarse_grained import (
    SimplePostalAddressCoarseGrained,
)


class ShippingInformation(object):
    """Implementation of the 'Shipping Information' model.

    The shipping information.

    Attributes:
        name (str): The recipient's name.
        method (str): The shipping method that is associated with this order.
        address (SimplePostalAddressCoarseGrained): A simple postal address with
            coarse-grained fields. Do not use for an international address. Use for
            backward compatibility only. Does not contain phone.
        secondary_shipping_address (SimplePostalAddressCoarseGrained): A simple
            postal address with coarse-grained fields. Do not use for an
            international address. Use for backward compatibility only. Does not
            contain phone.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "name": "name",
        "method": "method",
        "address": "address",
        "secondary_shipping_address": "secondary_shipping_address",
    }

    _optionals = [
        "name",
        "method",
        "address",
        "secondary_shipping_address",
    ]

    def __init__(
        self,
        name=APIHelper.SKIP,
        method=APIHelper.SKIP,
        address=APIHelper.SKIP,
        secondary_shipping_address=APIHelper.SKIP):
        """Initialize a ShippingInformation instance."""
        # Initialize members of the class
        if name is not APIHelper.SKIP:
            self.name = name
        if method is not APIHelper.SKIP:
            self.method = method
        if address is not APIHelper.SKIP:
            self.address = address
        if secondary_shipping_address is not APIHelper.SKIP:
            self.secondary_shipping_address = secondary_shipping_address

    @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
        name =\
            dictionary.get("name")\
            if dictionary.get("name")\
                else APIHelper.SKIP
        method =\
            dictionary.get("method")\
            if dictionary.get("method")\
                else APIHelper.SKIP
        address =\
            SimplePostalAddressCoarseGrained.from_dictionary(
                dictionary.get("address"))\
                if "address" in dictionary.keys()\
                else APIHelper.SKIP
        secondary_shipping_address =\
            SimplePostalAddressCoarseGrained.from_dictionary(
                dictionary.get("secondary_shipping_address"))\
                if "secondary_shipping_address" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(name,
                   method,
                   address,
                   secondary_shipping_address)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _method=(
            self.method
            if hasattr(self, "method")
            else None
        )
        _address=(
            self.address
            if hasattr(self, "address")
            else None
        )
        _secondary_shipping_address=(
            self.secondary_shipping_address
            if hasattr(self, "secondary_shipping_address")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!r}, "
            f"method={_method!r}, "
            f"address={_address!r}, "
            f"secondary_shipping_address={_secondary_shipping_address!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _method=(
            self.method
            if hasattr(self, "method")
            else None
        )
        _address=(
            self.address
            if hasattr(self, "address")
            else None
        )
        _secondary_shipping_address=(
            self.secondary_shipping_address
            if hasattr(self, "secondary_shipping_address")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!s}, "
            f"method={_method!s}, "
            f"address={_address!s}, "
            f"secondary_shipping_address={_secondary_shipping_address!s}, "
            f")"
        )
