"""cellpointapi.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.fulfilled_tax_line import (
    FulfilledTaxLine,
)
from cellpointapi.models.non_negative_amount import (
    NonNegativeAmount,
)


class FulfilledOrder(object):
    """Implementation of the 'FulfilledOrder' model.

    Contains the result of the order being fulfilled on the merchant's side.
    Includes information on what was fulfilled and unfulfilled so CPD can
    appropriately capture or cancel payments.

    Attributes:
        fulfillment_status (FulfillmentStatus): Result of the fulfillment.  On
            `PARTIAL`, the amount that was fulfilled must be specified.
        fulfilled_order_amount (NonNegativeAmount): An amount that is a nonnegative
            number, i.e. {0, 1, 2, 3, 4, 5,…}
        unfulfilled_order_amount (NonNegativeAmount): An amount that is a nonnegative
            number, i.e. {0, 1, 2, 3, 4, 5,…}
        tax_lines (List[FulfilledTaxLine]): The model property of type
            List[FulfilledTaxLine].
        line_items (List[FulfilledActivity | FulfilledAirlineAncillary |
            FulfilledAirlineFare | FulfilledAutoRental | FulfilledBundle |
            FulfilledDiscount | FulfilledLodgingReservation | FulfilledProduct] |
            None): The model property of type List[FulfilledActivity |
            FulfilledAirlineAncillary | FulfilledAirlineFare | FulfilledAutoRental |
            FulfilledBundle | FulfilledDiscount | FulfilledLodgingReservation |
            FulfilledProduct] | None.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "fulfillment_status": "fulfillmentStatus",
        "fulfilled_order_amount": "fulfilledOrderAmount",
        "unfulfilled_order_amount": "unfulfilledOrderAmount",
        "tax_lines": "taxLines",
        "line_items": "lineItems",
    }

    _optionals = [
        "fulfilled_order_amount",
        "unfulfilled_order_amount",
        "tax_lines",
        "line_items",
    ]

    def __init__(
        self,
        fulfillment_status=None,
        fulfilled_order_amount=APIHelper.SKIP,
        unfulfilled_order_amount=APIHelper.SKIP,
        tax_lines=APIHelper.SKIP,
        line_items=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a FulfilledOrder instance."""
        # Initialize members of the class
        self.fulfillment_status = fulfillment_status
        if fulfilled_order_amount is not APIHelper.SKIP:
            self.fulfilled_order_amount = fulfilled_order_amount
        if unfulfilled_order_amount is not APIHelper.SKIP:
            self.unfulfilled_order_amount = unfulfilled_order_amount
        if tax_lines is not APIHelper.SKIP:
            self.tax_lines = tax_lines
        if line_items is not APIHelper.SKIP:
            self.line_items = line_items

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @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.

        """
        from cellpointapi.utilities.union_type_lookup import (
            UnionTypeLookUp,
        )

        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        fulfillment_status =\
            dictionary.get("fulfillmentStatus")\
            if dictionary.get("fulfillmentStatus")\
                else None
        fulfilled_order_amount =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("fulfilledOrderAmount"))\
                if "fulfilledOrderAmount" in dictionary.keys()\
                else APIHelper.SKIP
        unfulfilled_order_amount =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("unfulfilledOrderAmount"))\
                if "unfulfilledOrderAmount" in dictionary.keys()\
                else APIHelper.SKIP
        tax_lines = None
        if dictionary.get("taxLines") is not None:
            tax_lines = [
                FulfilledTaxLine.from_dictionary(x)
                    for x in dictionary.get("taxLines")
            ]
        else:
            tax_lines = APIHelper.SKIP
        line_items = APIHelper.deserialize_union_type(
            UnionTypeLookUp.get("FulfilledLineItem"),
            dictionary.get("lineItems"),
            False)\
            if dictionary.get("lineItems") is not None\
            else APIHelper.SKIP

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(fulfillment_status,
                   fulfilled_order_amount,
                   unfulfilled_order_amount,
                   tax_lines,
                   line_items,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _fulfillment_status=self.fulfillment_status
        _fulfilled_order_amount=(
            self.fulfilled_order_amount
            if hasattr(self, "fulfilled_order_amount")
            else None
        )
        _unfulfilled_order_amount=(
            self.unfulfilled_order_amount
            if hasattr(self, "unfulfilled_order_amount")
            else None
        )
        _tax_lines=(
            self.tax_lines
            if hasattr(self, "tax_lines")
            else None
        )
        _line_items=(
            self.line_items
            if hasattr(self, "line_items")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"fulfillment_status={_fulfillment_status!r}, "
            f"fulfilled_order_amount={_fulfilled_order_amount!r}, "
            f"unfulfilled_order_amount={_unfulfilled_order_amount!r}, "
            f"tax_lines={_tax_lines!r}, "
            f"line_items={_line_items!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _fulfillment_status=self.fulfillment_status
        _fulfilled_order_amount=(
            self.fulfilled_order_amount
            if hasattr(self, "fulfilled_order_amount")
            else None
        )
        _unfulfilled_order_amount=(
            self.unfulfilled_order_amount
            if hasattr(self, "unfulfilled_order_amount")
            else None
        )
        _tax_lines=(
            self.tax_lines
            if hasattr(self, "tax_lines")
            else None
        )
        _line_items=(
            self.line_items
            if hasattr(self, "line_items")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"fulfillment_status={_fulfillment_status!s}, "
            f"fulfilled_order_amount={_fulfilled_order_amount!s}, "
            f"unfulfilled_order_amount={_unfulfilled_order_amount!s}, "
            f"tax_lines={_tax_lines!s}, "
            f"line_items={_line_items!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
