"""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 LineItem(object):
    """Implementation of the 'Line Item' model.

    The line items for this purchase. If your merchant account has been configured
    for Level 3 processing this field will be passed to the processor on your behalf.

    Attributes:
        name (str): The item name or title.
        quantity (str): The item quantity. Must be a whole number.
        description (str): The detailed item description.
        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.
        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.
        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.
        commodity_code (str): Code used to classify items purchased and track the
            total amount spent across various categories of products and services.
            Different corporate purchasing organizations may use different standards,
            but the United Nations Standard Products and Services Code (UNSPSC) is
            frequently used.
        discount_amount (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        total_amount (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        unit_of_measure (str): Unit of measure is a standard used to express the
            magnitude of a quantity in international trade. Most commonly used (but
            not limited to) examples are: Acre (ACR), Ampere (AMP), Centigram (CGM),
            Centimetre (CMT), Cubic inch (INQ), Cubic metre (MTQ), Fluid ounce (OZA),
            Foot (FOT), Hour (HUR), Item (ITM), Kilogram (KGM), Kilometre (KMT),
            Kilowatt (KWT), Liquid gallon (GLL), Liter (LTR), Pounds (LBS), Square
            foot (FTK).

    """

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

    _optionals = [
        "description",
        "sku",
        "url",
        "image_url",
        "upc",
        "billing_plan",
        "unit_amount",
        "tax",
        "commodity_code",
        "discount_amount",
        "total_amount",
        "unit_of_measure",
    ]

    def __init__(
        self,
        name=None,
        quantity=None,
        description=APIHelper.SKIP,
        sku=APIHelper.SKIP,
        url=APIHelper.SKIP,
        image_url=APIHelper.SKIP,
        upc=APIHelper.SKIP,
        billing_plan=APIHelper.SKIP,
        unit_amount=APIHelper.SKIP,
        tax=APIHelper.SKIP,
        commodity_code=APIHelper.SKIP,
        discount_amount=APIHelper.SKIP,
        total_amount=APIHelper.SKIP,
        unit_of_measure=APIHelper.SKIP):
        """Initialize a LineItem instance."""
        # Initialize members of the class
        self.name = name
        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 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
        if unit_amount is not APIHelper.SKIP:
            self.unit_amount = unit_amount
        if tax is not APIHelper.SKIP:
            self.tax = tax
        if commodity_code is not APIHelper.SKIP:
            self.commodity_code = commodity_code
        if discount_amount is not APIHelper.SKIP:
            self.discount_amount = discount_amount
        if total_amount is not APIHelper.SKIP:
            self.total_amount = total_amount
        if unit_of_measure is not APIHelper.SKIP:
            self.unit_of_measure = unit_of_measure

    @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
        quantity =\
            dictionary.get("quantity")\
            if dictionary.get("quantity")\
                else None
        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
        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
        unit_amount =\
            Money.from_dictionary(
                dictionary.get("unit_amount"))\
                if "unit_amount" in dictionary.keys()\
                else APIHelper.SKIP
        tax =\
            Money.from_dictionary(
                dictionary.get("tax"))\
                if "tax" in dictionary.keys()\
                else APIHelper.SKIP
        commodity_code =\
            dictionary.get("commodity_code")\
            if dictionary.get("commodity_code")\
                else APIHelper.SKIP
        discount_amount =\
            Money.from_dictionary(
                dictionary.get("discount_amount"))\
                if "discount_amount" in dictionary.keys()\
                else APIHelper.SKIP
        total_amount =\
            Money.from_dictionary(
                dictionary.get("total_amount"))\
                if "total_amount" in dictionary.keys()\
                else APIHelper.SKIP
        unit_of_measure =\
            dictionary.get("unit_of_measure")\
            if dictionary.get("unit_of_measure")\
                else APIHelper.SKIP

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

    def __repr__(self):
        """Return a unambiguous string representation."""
        _name=self.name
        _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
        )
        _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
        )
        _unit_amount=(
            self.unit_amount
            if hasattr(self, "unit_amount")
            else None
        )
        _tax=(
            self.tax
            if hasattr(self, "tax")
            else None
        )
        _commodity_code=(
            self.commodity_code
            if hasattr(self, "commodity_code")
            else None
        )
        _discount_amount=(
            self.discount_amount
            if hasattr(self, "discount_amount")
            else None
        )
        _total_amount=(
            self.total_amount
            if hasattr(self, "total_amount")
            else None
        )
        _unit_of_measure=(
            self.unit_of_measure
            if hasattr(self, "unit_of_measure")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!r}, "
            f"quantity={_quantity!r}, "
            f"description={_description!r}, "
            f"sku={_sku!r}, "
            f"url={_url!r}, "
            f"image_url={_image_url!r}, "
            f"upc={_upc!r}, "
            f"billing_plan={_billing_plan!r}, "
            f"unit_amount={_unit_amount!r}, "
            f"tax={_tax!r}, "
            f"commodity_code={_commodity_code!r}, "
            f"discount_amount={_discount_amount!r}, "
            f"total_amount={_total_amount!r}, "
            f"unit_of_measure={_unit_of_measure!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _name=self.name
        _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
        )
        _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
        )
        _unit_amount=(
            self.unit_amount
            if hasattr(self, "unit_amount")
            else None
        )
        _tax=(
            self.tax
            if hasattr(self, "tax")
            else None
        )
        _commodity_code=(
            self.commodity_code
            if hasattr(self, "commodity_code")
            else None
        )
        _discount_amount=(
            self.discount_amount
            if hasattr(self, "discount_amount")
            else None
        )
        _total_amount=(
            self.total_amount
            if hasattr(self, "total_amount")
            else None
        )
        _unit_of_measure=(
            self.unit_of_measure
            if hasattr(self, "unit_of_measure")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"name={_name!s}, "
            f"quantity={_quantity!s}, "
            f"description={_description!s}, "
            f"sku={_sku!s}, "
            f"url={_url!s}, "
            f"image_url={_image_url!s}, "
            f"upc={_upc!s}, "
            f"billing_plan={_billing_plan!s}, "
            f"unit_amount={_unit_amount!s}, "
            f"tax={_tax!s}, "
            f"commodity_code={_commodity_code!s}, "
            f"discount_amount={_discount_amount!s}, "
            f"total_amount={_total_amount!s}, "
            f"unit_of_measure={_unit_of_measure!s}, "
            f")"
        )
