from unittest.mock import MagicMock, patch, PropertyMock
from GramAddict.core.qdrant_memory import UIMemoryDB

def test_delete_point_logs_only_if_exists(caplog):
    # Setup
    db = UIMemoryDB()
    type(db).is_connected = PropertyMock(return_value=True)
    db.client = MagicMock()
    db.collection_name = "test_collection"

    # RED: Force the mock to return an empty list (point does NOT exist)
    db.client.retrieve.return_value = []

    # Action
    result = db.delete_point("fake_seed")

    # Assertions
    assert result is True  # Should still return True as it didn't crash
    # It should NOT call delete if it wasn't found
    db.client.delete.assert_not_called()
    # It should NOT log the "Purged poisoned memory" line
    assert "Purged poisoned memory vector" not in caplog.text

def test_delete_point_logs_if_found(caplog):
    # Setup
    db = UIMemoryDB()
    type(db).is_connected = PropertyMock(return_value=True)
    db.client = MagicMock()
    db.collection_name = "test_collection"

    # RED: Force the mock to return a result (point DOES exist)
    db.client.retrieve.return_value = [{"id": "some_uuid"}]

    # Action
    with patch("GramAddict.core.qdrant_memory.logger") as mock_logger:
        result = db.delete_point("fake_seed")

        # Assertions
        assert result is True
        db.client.delete.assert_called_once()
        mock_logger.info.assert_called_once()
        assert "Purged poisoned memory vector" in mock_logger.info.call_args[0][0]
