"""Tests for LLM adapters (import and instantiation only — no live API calls)."""

import tempfile
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest


class TestOpenAIAdapter:
    def test_import(self):
        from locidb.adapters.openai_adapter import LociMemory
        assert LociMemory is not None

    def test_instantiation(self, tmp_path):
        from locidb.adapters.openai_adapter import LociMemory
        mem = LociMemory(db_path=str(tmp_path / "test.loci"))
        stats = mem.db.stats()
        assert stats["node_count"] == 0
        mem.close()

    def test_entity_extraction(self):
        from locidb.adapters.openai_adapter import _extract_entities
        entities = _extract_entities('Optimize "Dropzi" delivery using Hub Spoke model')
        assert "Dropzi" in entities
        assert "Hub Spoke" in entities

    def test_format_memories_empty(self):
        from locidb.adapters.openai_adapter import _format_memories
        assert "No relevant" in _format_memories([])


class TestAnthropicAdapter:
    def test_import(self):
        from locidb.adapters.anthropic_adapter import LociAnthropicMemory
        assert LociAnthropicMemory is not None

    def test_instantiation(self, tmp_path):
        from locidb.adapters.anthropic_adapter import LociAnthropicMemory
        mem = LociAnthropicMemory(db_path=str(tmp_path / "test.loci"))
        stats = mem.db.stats()
        assert stats["node_count"] == 0
        mem.close()


class TestLangChainAdapter:
    def test_import(self):
        from locidb.adapters.langchain_adapter import LociLangChainMemory
        assert LociLangChainMemory is not None

    def test_instantiation(self, tmp_path):
        from locidb.adapters.langchain_adapter import LociLangChainMemory
        mem = LociLangChainMemory(db_path=str(tmp_path / "test.loci"))
        assert mem.memory_variables == ["history"]
        mem.close()

    def test_load_empty(self, tmp_path):
        from locidb.adapters.langchain_adapter import LociLangChainMemory
        mem = LociLangChainMemory(db_path=str(tmp_path / "test.loci"))
        result = mem.load_memory_variables({"input": ""})
        assert result["history"] == ""
        mem.close()
