"""Exceptions for the Django hook system."""


class HookSystemError(Exception):
    """Base exception for hook system operations."""

    pass


class HookRejectionError(HookSystemError):
    """
    Raised by PRE hooks to reject an operation.

    This exception allows PRE hooks to reject an operation before it executes,
    providing a machine-readable error code and human-readable message for
    frontend display.

    Attributes:
        error_code: Machine-readable error code in ALL_CAPS format (e.g., 'DAILY_LIMIT_EXCEEDED')
        message: Human-readable error message for display
        details: Optional dictionary with additional context for error handling

    Example:
        raise HookRejectionError(
            error_code="DAILY_LIMIT_EXCEEDED",
            message="You have exceeded your daily transaction limit of $500",
            details={
                "limit": 500,
                "current_total": 650,
                "remaining": 0,
            }
        )
    """

    def __init__(
        self,
        error_code: str,
        message: str,
        details: dict | None = None,
    ):
        super().__init__(message)
        self.error_code = error_code
        self.message = message
        self.details = details or {}


class HookExecutionError(HookSystemError):
    """
    Raised when a hook fails to execute due to an internal error.

    This is different from HookRejectionError - it represents a bug or system
    failure in the hook itself, not a business rule rejection.

    Attributes:
        message: Error description
        hook_name: Name of the hook that failed
        original_exception: The underlying exception that caused the failure
    """

    def __init__(self, message: str, hook_name: str, original_exception: Exception):
        super().__init__(message)
        self.hook_name = hook_name
        self.original_exception = original_exception
