import pytest
import numpy as np
from unittest import mock
from unittest.mock import MagicMock
from app.core.vector_store.faiss_store import FaissVectorStore
from app.core.vector_store.embedder.mock import MockEmbedder
from app.core.vector_store.embedder.genai import GenAIEmbedder

TEST_DIMENSION = 768

@pytest.fixture
def temp_faiss_file(tmp_path):
    test_dir = tmp_path / "faiss_test"
    test_dir.mkdir()
    return str(test_dir / "test_index.faiss")

@pytest.fixture
def mock_embedder():
    return MockEmbedder(dimension=TEST_DIMENSION)

@pytest.fixture
def mock_genai_embedder():
    with mock.patch('requests.post') as mock_post:
        embedding_data = np.random.rand(TEST_DIMENSION).tolist()
        mock_response = MagicMock()
        mock_response.raise_for_status.return_value = None
        mock_response.json.return_value = {"embedding": {"values": embedding_data}}
        mock_post.return_value = mock_response

        yield GenAIEmbedder("gemini-embedding-001", "mock_api_key", TEST_DIMENSION)

@pytest.fixture(params=[
    pytest.param('mock_embedder', id="MockEmbedder"),
    pytest.param('mock_genai_embedder', id="GenAIEmbedder")
])
def faiss_store(request, temp_faiss_file):
    embedder = request.getfixturevalue(request.param)
    store = FaissVectorStore(temp_faiss_file, TEST_DIMENSION, embedder)
    yield store
