"""Tests for undo_history tool."""

import pytest
from unittest.mock import AsyncMock, patch

from godotiq.tools.bridge.undo_history import undo_history


class TestUndoHistoryTool:
    @pytest.mark.asyncio
    async def test_basic_response(self):
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(return_value={
            "can_undo": True,
            "can_redo": False,
            "current_action": "GodotIQ: 1 node operation(s)",
            "godotiq_actions": [
                {"action": "GodotIQ: 1 node operation(s)", "operations": 1},
            ],
            "total_godotiq_actions": 1,
        })
        with patch("godotiq.tools.bridge.undo_history.get_bridge", return_value=mock_bridge):
            result = await undo_history()
            assert result["can_undo"] is True
            assert result["can_redo"] is False
            assert result["total_godotiq_actions"] == 1

    @pytest.mark.asyncio
    async def test_empty_history(self):
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(return_value={
            "can_undo": False,
            "can_redo": False,
            "current_action": "",
            "godotiq_actions": [],
            "total_godotiq_actions": 0,
        })
        with patch("godotiq.tools.bridge.undo_history.get_bridge", return_value=mock_bridge):
            result = await undo_history()
            assert result["total_godotiq_actions"] == 0

    @pytest.mark.asyncio
    async def test_timeout_value(self):
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(return_value={})
        with patch("godotiq.tools.bridge.undo_history.get_bridge", return_value=mock_bridge):
            await undo_history()
            call_kwargs = mock_bridge.request.call_args
            assert call_kwargs.kwargs.get("timeout") == 3.0 or call_kwargs[1].get("timeout") == 3.0
