"""Tests for Anthropic native tool base classes."""

import pytest
from nanobot.agent.tools.anthropic.base import (
    BaseAnthropicTool,
    ToolResult,
    CLIResult,
    ToolError,
)


class DummyTool(BaseAnthropicTool):
    """Test tool implementation."""
    api_type = "test_20250227"
    name = "test_tool"
    beta_flag = "test-beta"

    async def __call__(self, **kwargs):
        return ToolResult(output="test output")

    def to_params(self):
        return {"type": self.api_type, "name": self.name}


def test_tool_result_dataclass():
    """Test ToolResult can be created with all fields."""
    result = ToolResult(output="hello", error=None, base64_image=None, system="system message")
    assert result.output == "hello"
    assert result.error is None
    assert result.base64_image is None
    assert result.system == "system message"


def test_cli_result_dataclass():
    """Test CLIResult can be created with all fields."""
    result = CLIResult(exit_code=0, output="command output", error="")
    assert result.output == "command output"
    assert result.exit_code == 0
    assert result.error == ""


def test_tool_error_exception():
    """Test ToolError can be raised and caught."""
    with pytest.raises(ToolError):
        raise ToolError("Test error message")


def test_base_anthropic_tool_to_params():
    """Test tool returns correct params format."""
    tool = DummyTool()
    params = tool.to_params()
    assert params["type"] == "test_20250227"
    assert params["name"] == "test_tool"


@pytest.mark.asyncio
async def test_base_anthropic_tool_call():
    """Test tool can be called and returns ToolResult."""
    tool = DummyTool()
    result = await tool()
    assert isinstance(result, ToolResult)
    assert result.output == "test output"
