from unittest import TestCase
from pygeai.lab.managers import AILabManager
from pygeai.lab.plugins.tools.models import ToolParameter
from pygeai.core.common.exceptions import APIResponseError, MissingRequirementException


class TestAILabGetToolPluginConfigIntegration(TestCase):

    def setUp(self):
        self.ai_lab_manager = AILabManager()
        self.plugin_id = "test-plugin-id"

    def __get_tool_plugin_config(self, plugin_id: str = None):
        return self.ai_lab_manager.get_tool_plugin_config(
            plugin_id_or_name=self.plugin_id if plugin_id is None else plugin_id
        )

    def test_get_tool_plugin_config(self):
        tool_parameters = self.__get_tool_plugin_config()

        for param in tool_parameters:
            self.assertIsInstance(param, ToolParameter, "Expected a tool parameter")

    def test_get_tool_plugin_config_invalid_plugin_id(self):
        invalid_id = "invalid-plugin-id-12345"

        with self.assertRaises(APIResponseError) as exception:
            self.__get_tool_plugin_config(plugin_id=invalid_id)
        self.assertIn(
            f"Tool plugin not found",
            str(exception.exception),
            "Expected error when trying to send an invalid tool-plugin id"
        )

    def test_get_tool_plugin_config_no_plugin_id(self):
        with self.assertRaises(MissingRequirementException) as exception:
            self.__get_tool_plugin_config(plugin_id="")
        self.assertIn(
            "plugin_id_or_name must be provided",
            str(exception.exception),
            "Expected error when trying to send a request without plugin_id"
        )
