"""Burrow exception hierarchy."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from burrow import ScanResult


class BurrowError(Exception):
    """Base exception for all Burrow SDK errors."""


class BurrowBlockedError(BurrowError):
    """Raised when a scan result indicates the content was blocked."""

    def __init__(self, result: ScanResult):
        self.result = result
        super().__init__(f"Burrow blocked: {result.category} ({result.confidence:.0%} confidence)")


class BurrowAuthError(BurrowError):
    """Raised when OAuth credentials are invalid or revoked (401/403).

    This is always raised regardless of fail_open — credential failures
    are permanent and should never be silently swallowed.
    """

    def __init__(
        self,
        message: str = "OAuth credentials are invalid or have been revoked. "
        "Check your BURROW_CLIENT_ID and BURROW_CLIENT_SECRET.",
    ):
        super().__init__(message)


class BurrowQuotaError(BurrowError):
    """Raised when the tenant's monthly scan quota is exhausted.

    This is always raised regardless of fail_open — quota exhaustion is an
    intentional policy decision, not a transient infrastructure failure.
    """

    def __init__(
        self,
        message: str = (
            "Monthly scan quota exceeded. Upgrade your plan or wait for the next billing cycle."
        ),
    ):
        super().__init__(message)


class BurrowTimeoutError(BurrowError):
    """Raised when a Burrow API request times out."""
