"""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.payment_method import (
    PaymentMethod,
)


class SubscriptionPatchApplicationContext(object):
    """Implementation of the 'Subscription Patch Application Context' model.

    The application context, which customizes the payer experience during the
    subscription approval process with PayPal.

    Attributes:
        brand_name (str): The label that overrides the business name in the PayPal
            account on the PayPal site.
        locale (str): The BCP 47-formatted locale of pages that the PayPal payment
            experience shows. PayPal supports a five-character code. For example,
            `da-DK`, `he-IL`, `id-ID`, `ja-JP`, `no-NO`, `pt-BR`, `ru-RU`, `sv-SE`,
            `th-TH`, `zh-CN`, `zh-HK`, or `zh-TW`.
        shipping_preference (ExperienceContextShippingPreference): The location from
            which the shipping address is derived.
        payment_method (PaymentMethod): The customer and merchant payment preferences.
        return_url (str): The URL where the customer is redirected after the customer
            approves the payment.
        cancel_url (str): The URL where the customer is redirected after the customer
            cancels the payment.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "return_url": "return_url",
        "cancel_url": "cancel_url",
        "brand_name": "brand_name",
        "locale": "locale",
        "shipping_preference": "shipping_preference",
        "payment_method": "payment_method",
    }

    _optionals = [
        "brand_name",
        "locale",
        "shipping_preference",
        "payment_method",
    ]

    def __init__(
        self,
        return_url=None,
        cancel_url=None,
        brand_name=APIHelper.SKIP,
        locale=APIHelper.SKIP,
        shipping_preference="GET_FROM_FILE",
        payment_method=APIHelper.SKIP):
        """Initialize a SubscriptionPatchApplicationContext instance."""
        # Initialize members of the class
        if brand_name is not APIHelper.SKIP:
            self.brand_name = brand_name
        if locale is not APIHelper.SKIP:
            self.locale = locale
        self.shipping_preference = shipping_preference
        if payment_method is not APIHelper.SKIP:
            self.payment_method = payment_method
        self.return_url = return_url
        self.cancel_url = cancel_url

    @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
        return_url =\
            dictionary.get("return_url")\
            if dictionary.get("return_url")\
                else None
        cancel_url =\
            dictionary.get("cancel_url")\
            if dictionary.get("cancel_url")\
                else None
        brand_name =\
            dictionary.get("brand_name")\
            if dictionary.get("brand_name")\
                else APIHelper.SKIP
        locale =\
            dictionary.get("locale")\
            if dictionary.get("locale")\
                else APIHelper.SKIP
        shipping_preference =\
            dictionary.get("shipping_preference")\
            if dictionary.get("shipping_preference")\
                else "GET_FROM_FILE"
        payment_method =\
            PaymentMethod.from_dictionary(
                dictionary.get("payment_method"))\
                if "payment_method" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(return_url,
                   cancel_url,
                   brand_name,
                   locale,
                   shipping_preference,
                   payment_method)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _brand_name=(
            self.brand_name
            if hasattr(self, "brand_name")
            else None
        )
        _locale=(
            self.locale
            if hasattr(self, "locale")
            else None
        )
        _shipping_preference=(
            self.shipping_preference
            if hasattr(self, "shipping_preference")
            else None
        )
        _payment_method=(
            self.payment_method
            if hasattr(self, "payment_method")
            else None
        )
        _return_url=self.return_url
        _cancel_url=self.cancel_url
        return (
            f"{self.__class__.__name__}("
            f"brand_name={_brand_name!r}, "
            f"locale={_locale!r}, "
            f"shipping_preference={_shipping_preference!r}, "
            f"payment_method={_payment_method!r}, "
            f"return_url={_return_url!r}, "
            f"cancel_url={_cancel_url!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _brand_name=(
            self.brand_name
            if hasattr(self, "brand_name")
            else None
        )
        _locale=(
            self.locale
            if hasattr(self, "locale")
            else None
        )
        _shipping_preference=(
            self.shipping_preference
            if hasattr(self, "shipping_preference")
            else None
        )
        _payment_method=(
            self.payment_method
            if hasattr(self, "payment_method")
            else None
        )
        _return_url=self.return_url
        _cancel_url=self.cancel_url
        return (
            f"{self.__class__.__name__}("
            f"brand_name={_brand_name!s}, "
            f"locale={_locale!s}, "
            f"shipping_preference={_shipping_preference!s}, "
            f"payment_method={_payment_method!s}, "
            f"return_url={_return_url!s}, "
            f"cancel_url={_cancel_url!s}, "
            f")"
        )
