"""Tests for SDK exceptions.

Tests for query-only SDK exceptions. This SDK does NOT handle ingestion.
"""

import pytest

from fishinfo.exceptions import (
    FishinfoError,
    ConfigError,
    AuthenticationError,
    AuthorizationError,
    ValidationError,
    RateLimitError,
    ResourceNotFoundError,
    ServerError,
)


class TestExceptions:
    """Tests for exception classes."""

    def test_base_exception(self):
        """Test base FishinfoError."""
        error = FishinfoError("Test error", details={"key": "value"})

        assert str(error) == "Test error"
        assert error.message == "Test error"
        assert error.details == {"key": "value"}

    def test_config_error(self):
        """Test ConfigError."""
        error = ConfigError("Invalid configuration")

        assert isinstance(error, FishinfoError)
        assert str(error) == "Invalid configuration"

    def test_authentication_error(self):
        """Test AuthenticationError."""
        error = AuthenticationError("Invalid API key")

        assert isinstance(error, FishinfoError)
        assert str(error) == "Invalid API key"

    def test_authorization_error(self):
        """Test AuthorizationError."""
        error = AuthorizationError("Permission denied")

        assert isinstance(error, FishinfoError)
        assert str(error) == "Permission denied"

    def test_validation_error(self):
        """Test ValidationError with error list."""
        error = ValidationError(
            "Validation failed",
            errors=["Invalid latitude", "Missing field"],
            details={"field": "latitude"},
        )

        assert isinstance(error, FishinfoError)
        assert str(error) == "Validation failed"
        assert error.errors == ["Invalid latitude", "Missing field"]
        assert error.details == {"field": "latitude"}

    def test_rate_limit_error(self):
        """Test RateLimitError with retry_after."""
        error = RateLimitError("Rate limit exceeded", retry_after=60)

        assert isinstance(error, FishinfoError)
        assert str(error) == "Rate limit exceeded"
        assert error.retry_after == 60

    def test_resource_not_found_error(self):
        """Test ResourceNotFoundError."""
        error = ResourceNotFoundError("Vessel not found")

        assert isinstance(error, FishinfoError)
        assert str(error) == "Vessel not found"

    def test_server_error(self):
        """Test ServerError with status code."""
        error = ServerError("Internal server error", status_code=500)

        assert isinstance(error, FishinfoError)
        assert str(error) == "Internal server error"
        assert error.status_code == 500

    def test_exception_hierarchy(self):
        """Test exception hierarchy."""
        # All custom exceptions should inherit from FishinfoError
        assert issubclass(ConfigError, FishinfoError)
        assert issubclass(AuthenticationError, FishinfoError)
        assert issubclass(ValidationError, FishinfoError)
        assert issubclass(ServerError, FishinfoError)

        # FishinfoError should inherit from Exception
        assert issubclass(FishinfoError, Exception)

    def test_exception_catching(self):
        """Test catching exceptions."""
        try:
            raise ValidationError("Test error")
        except FishinfoError as e:
            assert isinstance(e, ValidationError)
            assert isinstance(e, FishinfoError)

        try:
            raise ServerError("Server error", status_code=500)
        except FishinfoError as e:
            assert isinstance(e, ServerError)
            assert e.status_code == 500
