"""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.authorization_group_full import (
    AuthorizationGroupFull,
)
from cellpointapi.models.non_negative_amount import (
    NonNegativeAmount,
)
from cellpointapi.models.tax import Tax


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

    Summary or breakdown of the pricing of each individual item
    being purchased as part of an order, along with the total cost to the Buyer.

    Attributes:
        line_items (List[Product | Activity | AirlineFare | AirlineAncillary |
            AutoRental | Bundle | Discount | LodgingReservation]): Line items that
            make up the order. Line items can include taxes and fees.  The type of
            line item is determined by the `type` property.
        tax_lines (List[Tax]): Tax lines to be added to the entire order.
        sub_total_price (NonNegativeAmount): Total of all lineItems, excluding all
            taxes and fees.
        total_price (NonNegativeAmount): Total cost of order to the buyer. Includes
            all taxes and fees.
        authorization_groups (List[AuthorizationGroupFull]): > If an authorization
            group exists, all top-level line items must correspond to an appropriate
            authorization group.  A means of grouping line items together into
            separate authorizations for Aggregate Payments.  As an example, if a
            buyer has the following line items:   1. Flight   2. Airport Lounge
            Access   3. Hotel    And Flight + Airport Lounge Access should be an
            authorization, while hotel is a separate authorization, then two
            authorization groups should be created.  E.g.: ```json [   {     "id":
            "PACKAGE",     "totalAmount": {       "currency": "USD",       "value":
            15000     }   },   {     "id": "INSURANCE",     "totalAmount": {
            "currency": "USD",       "value": 20000     }   } ] ```
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "line_items": "lineItems",
        "total_price": "totalPrice",
        "tax_lines": "taxLines",
        "sub_total_price": "subTotalPrice",
        "authorization_groups": "authorizationGroups",
    }

    _optionals = [
        "tax_lines",
        "sub_total_price",
        "authorization_groups",
    ]

    def __init__(
        self,
        line_items=None,
        total_price=None,
        tax_lines=APIHelper.SKIP,
        sub_total_price=APIHelper.SKIP,
        authorization_groups=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a PriceSummary instance."""
        # Initialize members of the class
        self.line_items = line_items
        if tax_lines is not APIHelper.SKIP:
            self.tax_lines = tax_lines
        if sub_total_price is not APIHelper.SKIP:
            self.sub_total_price = sub_total_price
        self.total_price = total_price
        if authorization_groups is not APIHelper.SKIP:
            self.authorization_groups = authorization_groups

        # 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
        line_items = APIHelper.deserialize_union_type(
            UnionTypeLookUp.get("LineItem"),
            dictionary.get("lineItems"),
            False)\
            if dictionary.get("lineItems") is not None\
            else None
        total_price =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("totalPrice"))\
                if dictionary.get("totalPrice") else None
        tax_lines = None
        if dictionary.get("taxLines") is not None:
            tax_lines = [
                Tax.from_dictionary(x)
                    for x in dictionary.get("taxLines")
            ]
        else:
            tax_lines = APIHelper.SKIP
        sub_total_price =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("subTotalPrice"))\
                if "subTotalPrice" in dictionary.keys()\
                else APIHelper.SKIP
        authorization_groups = None
        if dictionary.get("authorizationGroups") is not None:
            authorization_groups = [
                AuthorizationGroupFull.from_dictionary(x)
                    for x in dictionary.get("authorizationGroups")
            ]
        else:
            authorization_groups = 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(line_items,
                   total_price,
                   tax_lines,
                   sub_total_price,
                   authorization_groups,
                   additional_properties)

    @classmethod
    def validate(cls, dictionary):
        """Validate dictionary against class required properties

        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:
            boolean : if dictionary is valid contains required properties.

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

        if isinstance(dictionary, cls):
            return (UnionTypeLookUp.get("LineItem")
                .validate(dictionary.line_items).is_valid) \
                and APIHelper.is_valid_type(
                    value=dictionary.total_price,
                    type_callable=lambda value:
                        NonNegativeAmount.validate(value),
                    is_model_dict=True)

        if not isinstance(dictionary, dict):
            return False

        return (UnionTypeLookUp.get("LineItem")
            .validate(dictionary.get("lineItems")).is_valid) \
            and APIHelper.is_valid_type(
                value=dictionary.get("totalPrice"),
                type_callable=lambda value:
                    NonNegativeAmount.validate(value),
                is_model_dict=True)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _line_items=self.line_items
        _tax_lines=(
            self.tax_lines
            if hasattr(self, "tax_lines")
            else None
        )
        _sub_total_price=(
            self.sub_total_price
            if hasattr(self, "sub_total_price")
            else None
        )
        _total_price=self.total_price
        _authorization_groups=(
            self.authorization_groups
            if hasattr(self, "authorization_groups")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"line_items={_line_items!r}, "
            f"tax_lines={_tax_lines!r}, "
            f"sub_total_price={_sub_total_price!r}, "
            f"total_price={_total_price!r}, "
            f"authorization_groups={_authorization_groups!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _line_items=self.line_items
        _tax_lines=(
            self.tax_lines
            if hasattr(self, "tax_lines")
            else None
        )
        _sub_total_price=(
            self.sub_total_price
            if hasattr(self, "sub_total_price")
            else None
        )
        _total_price=self.total_price
        _authorization_groups=(
            self.authorization_groups
            if hasattr(self, "authorization_groups")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"line_items={_line_items!s}, "
            f"tax_lines={_tax_lines!s}, "
            f"sub_total_price={_sub_total_price!s}, "
            f"total_price={_total_price!s}, "
            f"authorization_groups={_authorization_groups!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
