"""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.exceptions.api_exception import (
    ApiException,
)
from paypalserversdk.models.link_description import (
    LinkDescription,
)
from paypalserversdk.models.transaction_search_error_details import (
    TransactionSearchErrorDetails,
)


class SearchErrorException(ApiException):
    def __init__(self, reason, response):
        """Initialize SearchErrorException object.

        Args:
            reason (string): The reason (or error message) for the Exception
                to be raised.
            response (HttpResponse): The HttpResponse of the API call.

        """
        super(SearchErrorException, self).__init__(reason, response)
        dictionary = APIHelper.json_deserialize(self.response.text)
        if isinstance(dictionary, dict):
            self.unbox(dictionary)

    def unbox(self, dictionary):
        """Populate the properties of this object by extracting them 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.

        """
        self.name =\
            dictionary.get("name")\
            if dictionary.get("name")\
                else None
        self.message =\
            dictionary.get("message")\
            if dictionary.get("message")\
                else None
        self.debug_id =\
            dictionary.get("debug_id")\
            if dictionary.get("debug_id")\
                else None
        self.information_link =\
            dictionary.get("information_link")\
            if dictionary.get("information_link")\
                else None
        self.details = None
        if dictionary.get("details") is not None:
            self.details = [
                TransactionSearchErrorDetails.from_dictionary(x)
                    for x in dictionary.get("details")
            ]
        else:
            self.details = None
        self.links = None
        if dictionary.get("links") is not None:
            self.links = [
                LinkDescription.from_dictionary(x)
                    for x in dictionary.get("links")
            ]
        else:
            self.links = None
        self.total_items =\
            dictionary.get("total_items")\
            if dictionary.get("total_items")\
                else None
        self.maximum_items =\
            dictionary.get("maximum_items")\
            if dictionary.get("maximum_items")\
                else None


    def __str__(self):
        """Return a human-readable string representation."""
        _name=self.name
        _message=self.message
        _debug_id=self.debug_id
        _information_link=(
            self.information_link
            if hasattr(self, "information_link")
            else None
        )
        _details=(
            self.details
            if hasattr(self, "details")
            else None
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        _total_items=(
            self.total_items
            if hasattr(self, "total_items")
            else None
        )
        _maximum_items=(
            self.maximum_items
            if hasattr(self, "maximum_items")
            else None
        )
        _base_str = super().__str__()
        _base_str = _base_str[_base_str.find("(") + 1:-1]
        return (
            f"{self.__class__.__name__}("
            f"base_str={_base_str!s}, "
            f"name={_name!s}, "
            f"message={_message!s}, "
            f"debug_id={_debug_id!s}, "
            f"information_link={_information_link!s}, "
            f"details={_details!s}, "
            f"links={_links!s}, "
            f"total_items={_total_items!s}, "
            f"maximum_items={_maximum_items!s}, "
            f")"
        )
