"""Error hierarchy for language handler system."""

from __future__ import annotations


class HandlerError(Exception):
    """Base error for handler system."""

    def __init__(self, message: str, context: dict[str, object] | None = None) -> None:
        super().__init__(message)
        self.context = context or {}


class LanguageNotFoundError(HandlerError):
    """Raised when no handler is registered for the requested language."""

    def __init__(self, language_id: str, available: list[str]) -> None:
        available_str = ", ".join(available) if available else "none"
        message = f"Language handler for '{language_id}' not found. Available: {available_str}"
        super().__init__(message, {"language_id": language_id, "available": available})


class HandlerNotImplementedError(HandlerError):
    """Raised when a handler doesn't support the requested feature."""

    def __init__(self, language_id: str, feature: str, capability: str) -> None:
        message = (
            f"Handler for '{language_id}' does not support {feature} capability '{capability}'. "
            f"Check handler.capabilities['{feature}']."
        )
        super().__init__(message, {"language_id": language_id, "feature": feature, "capability": capability})
