"""Tests for exception classes."""

from scottzach1.onepassword_cli.exceptions import (
    OnePasswordCLIError,
    OnePasswordException,
    OnePasswordNotAuthenticatedError,
    OnePasswordNotInstalledError,
    SecretInjectionError,
)


class TestOnePasswordException:
    """Tests for the base OnePasswordException class."""

    def test_initialization(self) -> None:
        """Test exception initialization with custom message."""
        exc = OnePasswordException("Test error message")
        assert exc.message == "Test error message"
        assert str(exc) == "Test error message"

    def test_repr(self) -> None:
        """Test exception representation."""
        exc = OnePasswordException("Test error")
        assert repr(exc) == "OnePasswordException('Test error')"

    def test_inheritance(self) -> None:
        """Test that it inherits from Exception."""
        exc = OnePasswordException("Test")
        assert isinstance(exc, Exception)


class TestOnePasswordCLIError:
    """Tests for OnePasswordCLIError class."""

    def test_initialization(self) -> None:
        """Test exception initialization."""
        exc = OnePasswordCLIError("CLI error")
        assert exc.message == "CLI error"
        assert str(exc) == "CLI error"

    def test_inheritance(self) -> None:
        """Test that it inherits from OnePasswordException."""
        exc = OnePasswordCLIError("Test")
        assert isinstance(exc, OnePasswordException)
        assert isinstance(exc, Exception)


class TestOnePasswordNotInstalledError:
    """Tests for OnePasswordNotInstalledError class."""

    def test_default_message(self) -> None:
        """Test that it has a helpful default message."""
        exc = OnePasswordNotInstalledError()
        assert "not found" in str(exc).lower()
        assert "install" in str(exc).lower()
        assert "https://developer.1password.com" in str(exc)

    def test_inheritance(self) -> None:
        """Test exception inheritance chain."""
        exc = OnePasswordNotInstalledError()
        assert isinstance(exc, OnePasswordCLIError)
        assert isinstance(exc, OnePasswordException)
        assert isinstance(exc, Exception)


class TestOnePasswordNotAuthenticatedError:
    """Tests for OnePasswordNotAuthenticatedError class."""

    def test_default_message(self) -> None:
        """Test that it has a helpful default message."""
        exc = OnePasswordNotAuthenticatedError()
        assert "not authenticated" in str(exc).lower()
        assert "op signin" in str(exc).lower()

    def test_inheritance(self) -> None:
        """Test exception inheritance chain."""
        exc = OnePasswordNotAuthenticatedError()
        assert isinstance(exc, OnePasswordCLIError)
        assert isinstance(exc, OnePasswordException)
        assert isinstance(exc, Exception)


class TestSecretInjectionError:
    """Tests for SecretInjectionError class."""

    def test_initialization_without_reference(self) -> None:
        """Test exception initialization without a reference."""
        exc = SecretInjectionError("Injection failed")
        assert exc.message == "Injection failed"
        assert str(exc) == "Injection failed"
        assert exc.reference is None

    def test_initialization_with_reference(self) -> None:
        """Test exception initialization with a reference."""
        exc = SecretInjectionError("Injection failed", reference="op://vault/item/field")
        assert "Injection failed" in exc.message
        assert "op://vault/item/field" in exc.message
        assert exc.reference == "op://vault/item/field"

    def test_repr_without_reference(self) -> None:
        """Test exception representation without a reference."""
        exc = SecretInjectionError("Test error")
        assert "SecretInjectionError" in repr(exc)
        assert "Test error" in repr(exc)

    def test_repr_with_reference(self) -> None:
        """Test exception representation with a reference."""
        exc = SecretInjectionError("Test error", reference="op://vault/item/field")
        representation = repr(exc)
        assert "SecretInjectionError" in representation
        assert "reference=" in representation
        assert "op://vault/item/field" in representation

    def test_inheritance(self) -> None:
        """Test exception inheritance chain."""
        exc = SecretInjectionError("Test")
        assert isinstance(exc, OnePasswordException)
        assert isinstance(exc, Exception)
        assert not isinstance(exc, OnePasswordCLIError)
