# Tables playground (cpp_apps.md / playgrounds.md). NO se indexa.
# Build flag FN_TQL_DUCKDB=ON activa el adapter tql_duckdb (issue 0080).
option(FN_TQL_DUCKDB "Enable DuckDB SQL execution adapter for tables playground" OFF)

set(_TABLES_SRC
    main.cpp
    data_table.cpp
    data_table_logic.cpp
    llm_anthropic.cpp
    lua_engine.cpp
    tql.cpp
    tql_to_sql.cpp
    viz.cpp
)
set(_TABLES_TEST_SRC
    self_test.cpp
    data_table_logic.cpp
    llm_anthropic.cpp
    lua_engine.cpp
    tql.cpp
    tql_to_sql.cpp
)
if(FN_TQL_DUCKDB)
    list(APPEND _TABLES_SRC tql_duckdb.cpp)
    list(APPEND _TABLES_TEST_SRC tql_duckdb.cpp)
endif()

add_imgui_app(tables_playground ${_TABLES_SRC})
target_link_libraries(tables_playground PRIVATE lua54 implot)
if(FN_TQL_DUCKDB)
    target_compile_definitions(tables_playground PRIVATE FN_TQL_DUCKDB=1)
    target_link_libraries(tables_playground PRIVATE duckdb_vendored)
    duckdb_copy_runtime(tables_playground)
endif()

# Self-test E2E (logica pura + lua_engine + tql).
add_executable(tables_playground_self_test ${_TABLES_TEST_SRC})
target_include_directories(tables_playground_self_test PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/functions
)
target_link_libraries(tables_playground_self_test PRIVATE lua54)
if(FN_TQL_DUCKDB)
    target_compile_definitions(tables_playground_self_test PRIVATE FN_TQL_DUCKDB=1)
    target_link_libraries(tables_playground_self_test PRIVATE duckdb_vendored)
    duckdb_copy_runtime(tables_playground_self_test)
endif()
