from __future__ import annotations


from any_llm.tools import callable_to_tool

from django_anyllm.registry import ModelRegistry
from django_anyllm.tools import get_tools

from .models import Author


class TestToolSchemaGeneration:
    """Smoke tests ensuring any-llm-sdk can convert our tools."""

    def test_all_tools_convert(self, db):
        registry = ModelRegistry()
        registry.register(Author)
        tools = get_tools(registry)

        for tool in tools:
            schema = callable_to_tool(tool)
            assert schema["type"] == "function"
            assert "function" in schema
            assert "name" in schema["function"]
            assert "description" in schema["function"]
            assert "parameters" in schema["function"]

    def test_tool_names(self, db):
        registry = ModelRegistry()
        registry.register(Author)
        tools = get_tools(registry)
        names = {t.__name__ for t in tools}
        expected = {
            "_list_registered_models",
            "_describe_model",
            "_get_model_schema",
            "_query_instances",
            "_get_instance",
            "_create_instance",
            "_update_instance",
            "_delete_instance",
            "_attach_file_to_instance",
        }
        assert names == expected
