"""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.address import Address
from paypalserversdk.models.phone_number_with_country_code import (
    PhoneNumberWithCountryCode,
)
from paypalserversdk.models.shipping_name import (
    ShippingName,
)
from paypalserversdk.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.
        email_address (str): The internationalized email address. Note: Up to 64
            characters are allowed before and 255 characters are allowed after the @
            sign. However, the generally accepted maximum length for an email address
            is 254 characters. The pattern verifies that an unquoted @ sign exists.
        phone_number (PhoneNumberWithCountryCode): The phone number in its canonical
            international [E.164 numbering plan
            format](https://www.itu.int/rec/T-REC-E.164/en).
        mtype (FulfillmentType): 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/libaddressinput/
            wiki/AddressValidationMetadata) and HTML 5.1 [Autofilling form controls:
            the autocomplete
            attribute](https://www.w3.org/TR/html51/sec-forms.html#autofilling-form-co
            ntrols-the-autocomplete-attribute).

    """

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

    _optionals = [
        "name",
        "email_address",
        "phone_number",
        "mtype",
        "options",
        "address",
    ]

    def __init__(
        self,
        name=APIHelper.SKIP,
        email_address=APIHelper.SKIP,
        phone_number=APIHelper.SKIP,
        mtype=APIHelper.SKIP,
        options=APIHelper.SKIP,
        address=APIHelper.SKIP):
        """Initialize a ShippingDetails instance."""
        # Initialize members of the class
        if name is not APIHelper.SKIP:
            self.name = name
        if email_address is not APIHelper.SKIP:
            self.email_address = email_address
        if phone_number is not APIHelper.SKIP:
            self.phone_number = phone_number
        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):
        """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 =\
            ShippingName.from_dictionary(
                dictionary.get("name"))\
                if "name" in dictionary.keys()\
                else APIHelper.SKIP
        email_address =\
            dictionary.get("email_address")\
            if dictionary.get("email_address")\
                else APIHelper.SKIP
        phone_number =\
            PhoneNumberWithCountryCode.from_dictionary(
                dictionary.get("phone_number"))\
                if "phone_number" 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,
                   email_address,
                   phone_number,
                   mtype,
                   options,
                   address)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _email_address=(
            self.email_address
            if hasattr(self, "email_address")
            else None
        )
        _phone_number=(
            self.phone_number
            if hasattr(self, "phone_number")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _options=(
            self.options
            if hasattr(self, "options")
            else None
        )
        _address=(
            self.address
            if hasattr(self, "address")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!r}, "
            f"email_address={_email_address!r}, "
            f"phone_number={_phone_number!r}, "
            f"mtype={_mtype!r}, "
            f"options={_options!r}, "
            f"address={_address!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _email_address=(
            self.email_address
            if hasattr(self, "email_address")
            else None
        )
        _phone_number=(
            self.phone_number
            if hasattr(self, "phone_number")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _options=(
            self.options
            if hasattr(self, "options")
            else None
        )
        _address=(
            self.address
            if hasattr(self, "address")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!s}, "
            f"email_address={_email_address!s}, "
            f"phone_number={_phone_number!s}, "
            f"mtype={_mtype!s}, "
            f"options={_options!s}, "
            f"address={_address!s}, "
            f")"
        )
