#[[
Copyright (c) 2014-2024 Key4hep-Project.

This file is part of Key4hep.
See https://key4hep.github.io/key4hep-doc/ for further info.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]

# Download the necessary data files dynamically
set(DATA_BASE_URL "https://key4hep.web.cern.ch/key4hep/k4ActsTracking/MuColl/data")
set(FILE_LIST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/file_list.txt")
set(OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

message(STATUS "Running download script for data files...")
execute_process(
  COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/download_files.sh" ${FILE_LIST_PATH} ${DATA_BASE_URL} ${OUTPUT_DIR}
  RESULT_VARIABLE download_result
  ERROR_VARIABLE download_error
)

if(download_result EQUAL 0)
  message(STATUS "Data files download completed successfully")
else()
  message(FATAL_ERROR "Failed to download data files:\n${download_error}")
endif()

# Tracking geometry
INSTALL(FILES MuColl_v1.root MuSIC_v1.root MuSIC_v2.root MAIA_v0.root
  DESTINATION ${CMAKE_INSTALL_DATADIR}/k4ActsTracking/data)

# Geometry description
INSTALL(FILES MuColl_v1.json MuSIC_v1.json MuSIC_v2.json MAIA_v0.json
  DESTINATION ${CMAKE_INSTALL_DATADIR}/k4ActsTracking/data)

# Material map
INSTALL(FILES material-maps.json MAIA_v0_material.json MAIA_v0_gen3_material_map.json
  DESTINATION ${CMAKE_INSTALL_DATADIR}/k4ActsTracking/data)
