# Prefer a system GoogleTest (Debian build images ship libgtest-dev); fall back
# to FetchContent so the test suite also configures on distros without it
# (e.g. the Void Linux dev host).
find_package(GTest QUIET)
if(NOT GTest_FOUND)
    message(STATUS "GTest not found on the system - fetching googletest")
    include(FetchContent)
    FetchContent_Declare(googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        GIT_TAG        v1.15.2)
    set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
    FetchContent_MakeAvailable(googletest)
endif()
include(GoogleTest)

add_executable(test_smoke test_smoke.cpp)
target_link_libraries(test_smoke PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_smoke)

add_executable(test_config test_config.cpp)
target_link_libraries(test_config PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_config)

add_executable(test_errors test_errors.cpp)
target_link_libraries(test_errors PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_errors)

add_executable(test_filters test_filters.cpp)
target_link_libraries(test_filters PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_filters)

add_executable(test_db_gateway test_db_gateway.cpp)
target_link_libraries(test_db_gateway PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_db_gateway)

add_executable(test_settings test_settings.cpp)
target_link_libraries(test_settings PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_settings)

add_executable(test_stores test_stores.cpp)
target_link_libraries(test_stores PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_stores)

add_executable(test_registry test_registry.cpp)
target_link_libraries(test_registry PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_registry)

add_executable(test_embeddings test_embeddings.cpp)
target_link_libraries(test_embeddings PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_embeddings)

add_executable(test_apikey test_apikey.cpp)
target_link_libraries(test_apikey PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_apikey)

add_executable(test_auth test_auth.cpp)
target_link_libraries(test_auth PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_auth)

add_executable(test_rate_limiter test_rate_limiter.cpp)
target_link_libraries(test_rate_limiter PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_rate_limiter)

add_executable(test_captcha test_captcha.cpp)
target_link_libraries(test_captcha PRIVATE vectorapi_core GTest::gtest_main)
gtest_discover_tests(test_captcha)

add_executable(test_api_integration test_api_integration.cpp)
target_link_libraries(test_api_integration PRIVATE vectorapi_core GTest::gtest_main)
target_compile_definitions(test_api_integration PRIVATE SVAPI_API_DOCS_DIR="${CMAKE_SOURCE_DIR}/api")
gtest_discover_tests(test_api_integration)
