"""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.money import Money
from paypalserversdk.models.order_billing_plan import (
    OrderBillingPlan,
)
from paypalserversdk.models.universal_product_code import (
    UniversalProductCode,
)


class ItemRequest(object):
    """Implementation of the 'Item Request' model.

    The details for the items to be purchased.

    Attributes:
        name (str): The item name or title.
        unit_amount (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        tax (Money): The currency and amount for a financial transaction, such as a
            balance or payment due.
        quantity (str): The item quantity. Must be a whole number.
        description (str): This field supports up to 4000 characters, but any content
            beyond 2048 characters (including spaces) will be truncated. The 2048
            character limit is reflected in the response representation of this field.
        sku (str): The stock keeping unit (SKU) for the item.
        url (str): The URL to the item being purchased. Visible to buyer and used in
            buyer experiences.
        category (ItemCategory): The item category type.
        image_url (str): The URL of the item's image. File type and size restrictions
            apply. An image that violates these restrictions will not be honored.
        upc (UniversalProductCode): The Universal Product Code of the item.
        billing_plan (OrderBillingPlan): Metadata for merchant-managed recurring
            billing plans. Valid only during the saved payment method token or
            billing agreement creation.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "name": "name",
        "unit_amount": "unit_amount",
        "quantity": "quantity",
        "tax": "tax",
        "description": "description",
        "sku": "sku",
        "url": "url",
        "category": "category",
        "image_url": "image_url",
        "upc": "upc",
        "billing_plan": "billing_plan",
    }

    _optionals = [
        "tax",
        "description",
        "sku",
        "url",
        "category",
        "image_url",
        "upc",
        "billing_plan",
    ]

    def __init__(
        self,
        name=None,
        unit_amount=None,
        quantity=None,
        tax=APIHelper.SKIP,
        description=APIHelper.SKIP,
        sku=APIHelper.SKIP,
        url=APIHelper.SKIP,
        category=APIHelper.SKIP,
        image_url=APIHelper.SKIP,
        upc=APIHelper.SKIP,
        billing_plan=APIHelper.SKIP):
        """Initialize a ItemRequest instance."""
        # Initialize members of the class
        self.name = name
        self.unit_amount = unit_amount
        if tax is not APIHelper.SKIP:
            self.tax = tax
        self.quantity = quantity
        if description is not APIHelper.SKIP:
            self.description = description
        if sku is not APIHelper.SKIP:
            self.sku = sku
        if url is not APIHelper.SKIP:
            self.url = url
        if category is not APIHelper.SKIP:
            self.category = category
        if image_url is not APIHelper.SKIP:
            self.image_url = image_url
        if upc is not APIHelper.SKIP:
            self.upc = upc
        if billing_plan is not APIHelper.SKIP:
            self.billing_plan = billing_plan

    @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 None
        unit_amount =\
            Money.from_dictionary(
                dictionary.get("unit_amount"))\
                if dictionary.get("unit_amount") else None
        quantity =\
            dictionary.get("quantity")\
            if dictionary.get("quantity")\
                else None
        tax =\
            Money.from_dictionary(
                dictionary.get("tax"))\
                if "tax" in dictionary.keys()\
                else APIHelper.SKIP
        description =\
            dictionary.get("description")\
            if dictionary.get("description")\
                else APIHelper.SKIP
        sku =\
            dictionary.get("sku")\
            if dictionary.get("sku")\
                else APIHelper.SKIP
        url =\
            dictionary.get("url")\
            if dictionary.get("url")\
                else APIHelper.SKIP
        category =\
            dictionary.get("category")\
            if dictionary.get("category")\
                else APIHelper.SKIP
        image_url =\
            dictionary.get("image_url")\
            if dictionary.get("image_url")\
                else APIHelper.SKIP
        upc =\
            UniversalProductCode.from_dictionary(
                dictionary.get("upc"))\
                if "upc" in dictionary.keys()\
                else APIHelper.SKIP
        billing_plan =\
            OrderBillingPlan.from_dictionary(
                dictionary.get("billing_plan"))\
                if "billing_plan" in dictionary.keys()\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(name,
                   unit_amount,
                   quantity,
                   tax,
                   description,
                   sku,
                   url,
                   category,
                   image_url,
                   upc,
                   billing_plan)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _name=self.name
        _unit_amount=self.unit_amount
        _tax=(
            self.tax
            if hasattr(self, "tax")
            else None
        )
        _quantity=self.quantity
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _sku=(
            self.sku
            if hasattr(self, "sku")
            else None
        )
        _url=(
            self.url
            if hasattr(self, "url")
            else None
        )
        _category=(
            self.category
            if hasattr(self, "category")
            else None
        )
        _image_url=(
            self.image_url
            if hasattr(self, "image_url")
            else None
        )
        _upc=(
            self.upc
            if hasattr(self, "upc")
            else None
        )
        _billing_plan=(
            self.billing_plan
            if hasattr(self, "billing_plan")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!r}, "
            f"unit_amount={_unit_amount!r}, "
            f"tax={_tax!r}, "
            f"quantity={_quantity!r}, "
            f"description={_description!r}, "
            f"sku={_sku!r}, "
            f"url={_url!r}, "
            f"category={_category!r}, "
            f"image_url={_image_url!r}, "
            f"upc={_upc!r}, "
            f"billing_plan={_billing_plan!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _name=self.name
        _unit_amount=self.unit_amount
        _tax=(
            self.tax
            if hasattr(self, "tax")
            else None
        )
        _quantity=self.quantity
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _sku=(
            self.sku
            if hasattr(self, "sku")
            else None
        )
        _url=(
            self.url
            if hasattr(self, "url")
            else None
        )
        _category=(
            self.category
            if hasattr(self, "category")
            else None
        )
        _image_url=(
            self.image_url
            if hasattr(self, "image_url")
            else None
        )
        _upc=(
            self.upc
            if hasattr(self, "upc")
            else None
        )
        _billing_plan=(
            self.billing_plan
            if hasattr(self, "billing_plan")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!s}, "
            f"unit_amount={_unit_amount!s}, "
            f"tax={_tax!s}, "
            f"quantity={_quantity!s}, "
            f"description={_description!s}, "
            f"sku={_sku!s}, "
            f"url={_url!s}, "
            f"category={_category!s}, "
            f"image_url={_image_url!s}, "
            f"upc={_upc!s}, "
            f"billing_plan={_billing_plan!s}, "
            f")"
        )
