import pytest
from utils.weaviate_db import WeaviateEngine

# Test case 1: Empty conditions list
def test_build_filter_empty_conditions():
    engine = WeaviateEngine("test_collection", None)
    result = engine.build_filter([])
    assert result is None

# Test case 2: Single condition
def test_build_filter_single_condition():
    engine = WeaviateEngine("test_collection", None)
    conditions = [{"key": "name", "match": "John"}]
    result = engine.build_filter(conditions)
    expected = {
        "operator": "And",
        "operands": [
            {
                "path": ["metadata.name"],
                "operator": "Equal",
                "valueString": "John"
            }
        ]
    }
    assert result == expected

# Test case 3: Multiple conditions
def test_build_filter_multiple_conditions():
    engine = WeaviateEngine("test_collection", None)
    conditions = [
        {"key": "name", "match": "John"},
        {"key": "age", "match": 30}
    ]
    result = engine.build_filter(conditions)
    expected = {
        "operator": "And",
        "operands": [
            {
                "path": ["metadata.name"],
                "operator": "Equal",
                "valueString": "John"
            },
            {
                "path": ["metadata.age"],
                "operator": "Equal",
                "valueString": "30"
            }
        ]
    }
    assert result == expected

# Test case 4: Missing key or match value
def test_build_filter_missing_key_or_match():
    engine = WeaviateEngine("test_collection", None)
    conditions = [{"key": "name"}, {"match": "John"}]
    result = engine.build_filter(conditions)
    assert result is None