# Web server - smartbotic-server binary

# Use relaxed warnings for webserver (it includes gRPC headers which use __int128)
set(SMARTBOTIC_WEBSERVER_WARNINGS
    -Wall
    -Wextra
    -Werror
    -Wno-unused-parameter
    -Wno-dangling-reference
    -Wno-pedantic      # Required for abseil __int128 support
    -Wno-overflow      # Required for abseil hash_set.h
)

# Create library for webserver components
add_library(smartbotic_webserver STATIC
    src/config.cpp
    src/http_server.cpp
    src/database_client.cpp
    src/auth_service.cpp
    src/user_service.cpp
    src/workspace_service.cpp
    src/group_service.cpp
    src/membership_service.cpp
    src/api_key_service.cpp
    src/collection_service.cpp
    src/document_service.cpp
    src/ws_handler.cpp
    src/view_service.cpp
    src/page_service.cpp
    src/permissions.cpp
    src/authorization_service.cpp
)

target_include_directories(smartbotic_webserver
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

target_compile_options(smartbotic_webserver PRIVATE ${SMARTBOTIC_WEBSERVER_WARNINGS})

target_link_libraries(smartbotic_webserver
    PUBLIC
        smartbotic::common
        smartbotic::proto
        spdlog::spdlog
        nlohmann_json::nlohmann_json
        httplib::httplib
        PkgConfig::LWS
        OpenSSL::SSL
        OpenSSL::Crypto
        jwt-cpp::jwt-cpp
)

add_library(smartbotic::webserver ALIAS smartbotic_webserver)

# Create the executable
add_executable(smartbotic-crm-webserver
    src/main.cpp
)

target_include_directories(smartbotic-crm-webserver
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_compile_options(smartbotic-crm-webserver PRIVATE ${SMARTBOTIC_WEBSERVER_WARNINGS})

target_link_libraries(smartbotic-crm-webserver
    PRIVATE
        smartbotic::webserver
        smartbotic::common
        smartbotic::proto
        spdlog::spdlog
        nlohmann_json::nlohmann_json
)
