class Error(Exception):
    """Base exception."""

    pass


class RequestError(Error):
    """Errors while preparing or performing an API request."""

    pass


class RequestSetupError(RequestError):
    """Errors while preparing an API request."""

    pass


class IdentifierError(RequestSetupError):
    """Errors related to invalid resource identifiers that will be requested from the API."""

    pass


class ResponseHandlingError(Error):
    """Errors related to handling the response from the API."""

    pass


class ResponseError(Error):
    """Errors reported by the API."""

    status = None
    field = None

    def __init__(self, resp=None):
        message = resp['detail']
        super().__init__(message)
        self.status = resp['status']
        if 'field' in resp:
            self.field = resp['field']

    @staticmethod
    def factory(resp):
        """Return a ResponseError subclass based on the API payload.

        All errors are documented: https://docs.mollie.com/guides/handling-errors#all-possible-status-codes
        More exceptions should be added here when appropriate, and when useful examples of API errors are available.
        """
        status = resp['status']
        if status == 401:
            return UnauthorizedError(resp)
        elif status == 404:
            return NotFoundError(resp)
        elif status == 422:
            return UnprocessableEntityError(resp)
        else:
            # generic fallback
            return ResponseError(resp)


class UnauthorizedError(ResponseError):
    """Your request wasn't executed due to failed authentication. Check your API key."""

    pass


class NotFoundError(ResponseError):
    """The object referenced by your API request does not exist."""

    pass


class UnprocessableEntityError(ResponseError):
    """We could not process your request due to another reason than the ones listed above.

    The response usually contains a field property to indicate which field is causing the issue.
    """

    pass


class DataConsistencyError(Error):
    """We could not process the API response due to an inconsistency.

    We received different data than expected from the API.
    """

    pass


"""
Deprecation policy

When a minor version release will be done, remove all code that triggers the DeprecationWarning subclass.
Then rename the DeprecationWarning subclass to the next minor version (RemovedIn23Warning => RemovedIn24Warning).
and rename the PendingDeprecation subclass below also.

This will make all existing PendingDeprecationWarnings change to DeprecationWarnings.

This deprecation policy is similar to what is used in Django and Django-rest-framework.
See https://www.django-rest-framework.org/community/release-notes/#deprecation-policy for details.
"""


class RemovedIn23Warning(DeprecationWarning):
    """Deprecation warning for features that will be removed in version 2.3.0."""

    pass


class RemovedIn24Warning(PendingDeprecationWarning):
    """Pending deprecation warning for features that will be removed in version 2.4.0."""

    pass

@@ -2412,25 +2412,25 @@
  (RemovedIn2
-3
+4
 Warning =%3E R
@@ -2434,25 +2434,25 @@
 %3E RemovedIn2
-4
+5
 Warning).%0Aan
@@ -2801,17 +2801,17 @@
 movedIn2
-3
+4
 Warning(
@@ -2909,9 +2909,9 @@
 n 2.
-3
+4
 .0.%22
@@ -2933,33 +2933,33 @@
 class RemovedIn2
-4
+5
 Warning(PendingD
@@ -3052,33 +3052,33 @@
 ed in version 2.
-4
+5
 .0.%22%22%22%0A%0A    pass

Rename warning subclasses.