"""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.link_description import (
    LinkDescription,
)


class ErrorDetails(object):
    """Implementation of the 'Error Details' model.

    The error details. Required for client-side `4XX` errors.

    Attributes:
        field (str): The field that caused the error. If this field is in the body,
            set this value to the field's JSON pointer value. Required for
            client-side errors.
        value (str): The value of the field that caused the error.
        location (str): The location of the field that caused the error. Value is
            `body`, `path`, or `query`.
        issue (str): The unique, fine-grained application-level error code.
        links (List[LinkDescription]): An array of request-related [HATEOAS
            links](/api/rest/responses/#hateoas-links) that are either relevant to
            the issue by providing additional information or offering potential
            resolutions.
        description (str): The human-readable description for an issue. The
            description can change over the lifetime of an API, so clients must not
            depend on this value.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "issue": "issue",
        "field": "field",
        "value": "value",
        "location": "location",
        "links": "links",
        "description": "description",
    }

    _optionals = [
        "field",
        "value",
        "location",
        "links",
        "description",
    ]

    def __init__(
        self,
        issue=None,
        field=APIHelper.SKIP,
        value=APIHelper.SKIP,
        location="body",
        links=APIHelper.SKIP,
        description=APIHelper.SKIP):
        """Initialize a ErrorDetails instance."""
        # Initialize members of the class
        if field is not APIHelper.SKIP:
            self.field = field
        if value is not APIHelper.SKIP:
            self.value = value
        self.location = location
        self.issue = issue
        if links is not APIHelper.SKIP:
            self.links = links
        if description is not APIHelper.SKIP:
            self.description = description

    @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
        issue =\
            dictionary.get("issue")\
            if dictionary.get("issue")\
                else None
        field =\
            dictionary.get("field")\
            if dictionary.get("field")\
                else APIHelper.SKIP
        value =\
            dictionary.get("value")\
            if dictionary.get("value")\
                else APIHelper.SKIP
        location =\
            dictionary.get("location")\
            if dictionary.get("location")\
                else "body"
        links = None
        if dictionary.get("links") is not None:
            links = [
                LinkDescription.from_dictionary(x)
                    for x in dictionary.get("links")
            ]
        else:
            links = APIHelper.SKIP
        description =\
            dictionary.get("description")\
            if dictionary.get("description")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(issue,
                   field,
                   value,
                   location,
                   links,
                   description)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _field=(
            self.field
            if hasattr(self, "field")
            else None
        )
        _value=(
            self.value
            if hasattr(self, "value")
            else None
        )
        _location=(
            self.location
            if hasattr(self, "location")
            else None
        )
        _issue=self.issue
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"field={_field!r}, "
            f"value={_value!r}, "
            f"location={_location!r}, "
            f"issue={_issue!r}, "
            f"links={_links!r}, "
            f"description={_description!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _field=(
            self.field
            if hasattr(self, "field")
            else None
        )
        _value=(
            self.value
            if hasattr(self, "value")
            else None
        )
        _location=(
            self.location
            if hasattr(self, "location")
            else None
        )
        _issue=self.issue
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"field={_field!s}, "
            f"value={_value!s}, "
            f"location={_location!s}, "
            f"issue={_issue!s}, "
            f"links={_links!s}, "
            f"description={_description!s}, "
            f")"
        )
