"""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.amount import Amount
from cellpointapi.models.fulfillment_status import (
    FulfillmentStatus,
)
from cellpointapi.models.non_negative_amount import (
    NonNegativeAmount,
)


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

    A tax line that has been fulfilled.

    Attributes:
        title (str): What should be shown as the title of the line item on a receipt
            or billing summary.
        code (str): Code defined by government entity to identify a particular type
            of tax.
        price (NonNegativeAmount): An amount that is a nonnegative number, i.e. {0,
            1, 2, 3, 4, 5,…}
        authorization_group_id (str): AuthorizationGroup that the line item should be
            part of for splitting authorizations for Aggregate Payments.  If this is
            set, there must be a matching AuthorizationGroup created in the
            PriceSummary.  > NOTE: Items within a Bundle should not have an
            `authorizationGroupId`, they will use the same `authorizationGroupId` as
            the top-level bundle.
        fulfillment_status (FulfillmentStatus): Result of the fulfillment.  On
            `PARTIAL`, the amount that was fulfilled must be specified.
        fulfilled_price (Amount): Conditional property that should be sent if
            `fulfillmentStatus` is `PARTIAL`.  `fulfilledPrice` must be less than or
            equal to original `price`.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "title": "title",
        "price": "price",
        "fulfillment_status": "fulfillmentStatus",
        "code": "code",
        "authorization_group_id": "authorizationGroupId",
        "fulfilled_price": "fulfilledPrice",
    }

    _optionals = [
        "code",
        "authorization_group_id",
        "fulfilled_price",
    ]

    def __init__(
        self,
        title=None,
        price=None,
        fulfillment_status=None,
        code=APIHelper.SKIP,
        authorization_group_id=APIHelper.SKIP,
        fulfilled_price=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a FulfilledTaxLine instance."""
        # Initialize members of the class
        self.title = title
        if code is not APIHelper.SKIP:
            self.code = code
        self.price = price
        if authorization_group_id is not APIHelper.SKIP:
            self.authorization_group_id = authorization_group_id
        self.fulfillment_status = fulfillment_status
        if fulfilled_price is not APIHelper.SKIP:
            self.fulfilled_price = fulfilled_price

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

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

        # Extract variables from the dictionary
        title =\
            dictionary.get("title")\
            if dictionary.get("title")\
                else None
        price =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("price"))\
                if dictionary.get("price") else None
        fulfillment_status =\
            dictionary.get("fulfillmentStatus")\
            if dictionary.get("fulfillmentStatus")\
                else None
        code =\
            dictionary.get("code")\
            if dictionary.get("code")\
                else APIHelper.SKIP
        authorization_group_id =\
            dictionary.get("authorizationGroupId")\
            if dictionary.get("authorizationGroupId")\
                else APIHelper.SKIP
        fulfilled_price =\
            Amount.from_dictionary(
                dictionary.get("fulfilledPrice"))\
                if "fulfilledPrice" in dictionary.keys()\
                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(title,
                   price,
                   fulfillment_status,
                   code,
                   authorization_group_id,
                   fulfilled_price,
                   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.

        """
        if isinstance(dictionary, cls):
            return APIHelper.is_valid_type(
                    value=dictionary.title,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.price,
                    type_callable=lambda value:
                        NonNegativeAmount.validate(value),
                    is_model_dict=True) \
                and APIHelper.is_valid_type(
                    value=dictionary.fulfillment_status,
                    type_callable=lambda value:
                        FulfillmentStatus.validate(value))

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("title"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("price"),
                type_callable=lambda value:
                    NonNegativeAmount.validate(value),
                is_model_dict=True) \
            and APIHelper.is_valid_type(
                value=dictionary.get("fulfillmentStatus"),
                type_callable=lambda value:
                    FulfillmentStatus.validate(value))

    def __repr__(self):
        """Return a unambiguous string representation."""
        _title=self.title
        _code=(
            self.code
            if hasattr(self, "code")
            else None
        )
        _price=self.price
        _authorization_group_id=(
            self.authorization_group_id
            if hasattr(self, "authorization_group_id")
            else None
        )
        _fulfillment_status=self.fulfillment_status
        _fulfilled_price=(
            self.fulfilled_price
            if hasattr(self, "fulfilled_price")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"title={_title!r}, "
            f"code={_code!r}, "
            f"price={_price!r}, "
            f"authorization_group_id={_authorization_group_id!r}, "
            f"fulfillment_status={_fulfillment_status!r}, "
            f"fulfilled_price={_fulfilled_price!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _title=self.title
        _code=(
            self.code
            if hasattr(self, "code")
            else None
        )
        _price=self.price
        _authorization_group_id=(
            self.authorization_group_id
            if hasattr(self, "authorization_group_id")
            else None
        )
        _fulfillment_status=self.fulfillment_status
        _fulfilled_price=(
            self.fulfilled_price
            if hasattr(self, "fulfilled_price")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"title={_title!s}, "
            f"code={_code!s}, "
            f"price={_price!s}, "
            f"authorization_group_id={_authorization_group_id!s}, "
            f"fulfillment_status={_fulfillment_status!s}, "
            f"fulfilled_price={_fulfilled_price!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
