cmake_minimum_required(VERSION 3.22.1)
project(sandbox-test)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find dependencies via vcpkg
find_package(Lua REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)

# Sandbox library (the code being tested)
add_library(mosis-sandbox STATIC
    ../src/main/cpp/sandbox/lua_sandbox.cpp
    ../src/main/cpp/sandbox/permission_gate.cpp
    ../src/main/cpp/sandbox/audit_log.cpp
    ../src/main/cpp/sandbox/rate_limiter.cpp
    ../src/main/cpp/sandbox/path_sandbox.cpp
    ../src/main/cpp/sandbox/timer_manager.cpp
    ../src/main/cpp/sandbox/json_api.cpp
    ../src/main/cpp/sandbox/crypto_api.cpp
    ../src/main/cpp/sandbox/virtual_fs.cpp
    ../src/main/cpp/sandbox/database_manager.cpp
    ../src/main/cpp/sandbox/http_validator.cpp
    ../src/main/cpp/sandbox/network_manager.cpp
    ../src/main/cpp/sandbox/websocket_manager.cpp
    ../src/main/cpp/sandbox/camera_interface.cpp
    ../src/main/cpp/sandbox/microphone_interface.cpp
    ../src/main/cpp/sandbox/audio_output.cpp
    ../src/main/cpp/sandbox/location_interface.cpp
    ../src/main/cpp/sandbox/sensor_interface.cpp
    ../src/main/cpp/sandbox/bluetooth_interface.cpp
    ../src/main/cpp/sandbox/contacts_interface.cpp
    ../src/main/cpp/sandbox/message_bus.cpp
    ../src/main/cpp/sandbox/sandbox_manager.cpp
)
target_include_directories(mosis-sandbox PUBLIC
    ../src/main/cpp/sandbox
    ${LUA_INCLUDE_DIR}
)
target_link_libraries(mosis-sandbox PUBLIC
    ${LUA_LIBRARIES}
    nlohmann_json::nlohmann_json
    unofficial::sqlite3::sqlite3
)
# Windows BCrypt for crypto API
if(WIN32)
    target_link_libraries(mosis-sandbox PUBLIC bcrypt)
endif()

# Test executable
add_executable(sandbox-test
    src/main.cpp
    src/test_harness.cpp
    src/lua_fuzzer.cpp
)

target_include_directories(sandbox-test PRIVATE
    src
    ../src/main/cpp/sandbox
)

target_link_libraries(sandbox-test PRIVATE
    mosis-sandbox
    nlohmann_json::nlohmann_json
)

# Copy test scripts to build directory
add_custom_command(TARGET sandbox-test POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
        ${CMAKE_CURRENT_SOURCE_DIR}/scripts
        $<TARGET_FILE_DIR:sandbox-test>/scripts
)

# Windows-specific
if(WIN32)
    target_compile_definitions(sandbox-test PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
