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

"""
paypalserversdk

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
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):
        """Constructor for the ItemRequest class"""

        # 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):
        """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 = 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 (f'{self.__class__.__name__}('
                f'name={self.name!r}, '
                f'unit_amount={self.unit_amount!r}, '
                f'tax={(self.tax if hasattr(self, "tax") else None)!r}, '
                f'quantity={self.quantity!r}, '
                f'description={(self.description if hasattr(self, "description") else None)!r}, '
                f'sku={(self.sku if hasattr(self, "sku") else None)!r}, '
                f'url={(self.url if hasattr(self, "url") else None)!r}, '
                f'category={(self.category if hasattr(self, "category") else None)!r}, '
                f'image_url={(self.image_url if hasattr(self, "image_url") else None)!r}, '
                f'upc={(self.upc if hasattr(self, "upc") else None)!r}, '
                f'billing_plan={(self.billing_plan if hasattr(self, "billing_plan") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'name={self.name!s}, '
                f'unit_amount={self.unit_amount!s}, '
                f'tax={(self.tax if hasattr(self, "tax") else None)!s}, '
                f'quantity={self.quantity!s}, '
                f'description={(self.description if hasattr(self, "description") else None)!s}, '
                f'sku={(self.sku if hasattr(self, "sku") else None)!s}, '
                f'url={(self.url if hasattr(self, "url") else None)!s}, '
                f'category={(self.category if hasattr(self, "category") else None)!s}, '
                f'image_url={(self.image_url if hasattr(self, "image_url") else None)!s}, '
                f'upc={(self.upc if hasattr(self, "upc") else None)!s}, '
                f'billing_plan={(self.billing_plan if hasattr(self, "billing_plan") else None)!s})')
