import unittest
from pygeai.lab.plugins.tools.mappers import ToolPluginMapper
from pygeai.lab.models import ToolPlugin, ToolPluginList


class TestToolPluginMapper(unittest.TestCase):

    def test_map_to_tool_plugin_success(self):
        data = {
            "name": "TestPlugin",
            "id": "plugin-123"
        }
        result = ToolPluginMapper.map_to_tool_plugin(data)

        self.assertIsInstance(result, ToolPlugin)
        self.assertEqual(result.name, "TestPlugin")
        self.assertEqual(result.id, "plugin-123")

    def test_map_to_tool_plugin_nested_data(self):
        data = {
            "plugin": {
                "name": "NestedPlugin",
                "id": "nested-123"
            }
        }
        result = ToolPluginMapper.map_to_tool_plugin(data)

        self.assertIsInstance(result, ToolPlugin)
        self.assertEqual(result.name, "NestedPlugin")
        self.assertEqual(result.id, "nested-123")

    def test_map_to_tool_plugin_list_success(self):
        data = {
            "plugins": [
                {
                    "name": "Plugin1",
                    "id": "p1"
                },
                {
                    "name": "Plugin2",
                    "id": "p2"
                }
            ]
        }
        result = ToolPluginMapper.map_to_tool_plugin_list(data)

        self.assertIsInstance(result, ToolPluginList)
        self.assertEqual(len(result.plugins), 2)
        self.assertIsInstance(result.plugins[0], ToolPlugin)
        self.assertEqual(result.plugins[0].name, "Plugin1")
        self.assertEqual(result.plugins[1].name, "Plugin2")

    def test_map_to_tool_plugin_list_empty(self):
        data = {"plugins": []}
        result = ToolPluginMapper.map_to_tool_plugin_list(data)

        self.assertIsInstance(result, ToolPluginList)
        self.assertEqual(len(result.plugins), 0)


if __name__ == '__main__':
    unittest.main()
