# Each folder is a module with its own library. A module's sources can
# include only its own headers and those of the libraries it links to,
# so the target_link_libraries lines below are the dependency graph.

# Low-level detail: the (simulated) database client. Depends on nothing.
add_library(principles_dip_kv STATIC kv_store/kv_store.cpp)
target_include_directories(principles_dip_kv PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/kv_store)

# High-level policy: the order rules and the interface they own.
# Depends on nothing either.
add_library(principles_dip_orders STATIC orders/order.cpp orders/order_service.cpp)
target_include_directories(principles_dip_orders PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/orders)

# The adapter: the only module that depends on both.
add_library(principles_dip_kv_orders STATIC kv_orders/kv_order_repository.cpp)
target_include_directories(principles_dip_kv_orders PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/kv_orders)
target_link_libraries(principles_dip_kv_orders PUBLIC principles_dip_orders principles_dip_kv)

# Before: the order rules depend directly on the database client.
add_library(principles_dip_before STATIC before/before.cpp)
target_include_directories(principles_dip_before PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/before)
target_link_libraries(principles_dip_before PUBLIC principles_dip_orders principles_dip_kv)

lld_add_example(principles_dip SOURCES main.cpp EXPECTED_OUTPUT expected_output.txt)
target_link_libraries(principles_dip PRIVATE principles_dip_kv_orders principles_dip_before)

# The rules are tested without the database client or the adapter.
lld_add_test(principles_dip_orders_tests SOURCES test_order_service.cpp)
target_link_libraries(principles_dip_orders_tests PRIVATE principles_dip_orders)

lld_add_test(principles_dip_kv_orders_tests SOURCES test_kv_order_repository.cpp)
target_link_libraries(principles_dip_kv_orders_tests PRIVATE principles_dip_kv_orders principles_dip_before)
