"""Errors for actions app.

Version Added:
    6.0
"""

from __future__ import annotations

from housekeeping import ClassDeprecatedMixin

from reviewboard.deprecation import RemovedInReviewBoard10_0Warning


class ActionError(Exception):
    """Base class for action-related errors.

    Version:
        8.0
    """


class MissingActionRendererError(ActionError):
    """An error indicating an action renderer could not be found.

    Version:
        8.0
    """


class DepthLimitExceededError(ClassDeprecatedMixin,
                              ValueError,
                              warning_cls=RemovedInReviewBoard10_0Warning):
    """An error that occurs when the maximum depth limit is exceeded.

    Actions cannot be arbitrarily nested. For example, if the depth limit is 2,
    then this error would be triggered if an extension tried to add a menu
    action as follows:

    .. code-block:: python

       ActionHook(self, actions=[
           DepthZeroMenuAction(),
           DepthOneFirstItemAction(),
           DepthOneMenuAction(),
           DepthTwoMenuAction(),  # This depth is acceptable.
           DepthThreeTooDeepAction(),  # This action is too deep.
       ])

    Deprecated:
        8.0:
        This class is no longer used. It will be removed in Review Board 10.

    Version Added:
        6.0
    """

    def __init__(
        self,
        action_id: str,
        *,
        depth_limit: int,
    ) -> None:
        """Initialize the error.

        Args:
            action_id (str):
                The ID of the action which was too deep.

            depth_limit (int):
                The maximum depth which was exceeded.
        """
        super().__init__('%s exceeds the maximum depth limit of %d'
                         % (action_id, depth_limit))
