services:
  neo4j:
    image: neo4j:5.7
    environment:
      - NEO4J_AUTH=${NEO4J_AUTH:-neo4j/password}
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_server_config_strict__validation_enabled=false
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      - SHARED_PATH=/neo4j_import
    command: >
      bash -c '
        echo "running cmd from docker compose" &&
        #neo4j start &&
        while true; do
          if [ -f /neo4j_import/ready-to-import ]; then
            echo "Starting import process..."
            neo4j stop &&
            bash /neo4j_import/neo4j-admin-import-call.sh &&
            rm /neo4j_import/ready-to-import &&
            touch /neo4j_import/import-complete &&
            chmod 777 /neo4j_import/import-complete
            neo4j start
            echo "The container is running. STR+C will end the bash command and thus, the neo4j container"
          fi
          sleep 10
        done
      '
    healthcheck:
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:7474 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - "8080:7474"
      - "8081:7687"
    volumes:
      - neo4j_data:/neo4j_data
      - neo4j_logs:/neo4j_logs
      - neo4j_import:/neo4j_import
      - ${INPUT_DATA_PATH:-./data}:/input_data
      - ./init-scripts:/init-scripts
      - ./importData:/importData


  python_app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        HTTP_PROXY: ${HTTP_PROXY}
        HTTPS_PROXY: ${HTTPS_PROXY}
        NO_PROXY: ${NO_PROXY}
    env_file:
         - .env
    environment:
      - NEO4J_URI=bolt://neo4j:7687
      - NEO4J_USER=${NEO4J_USER:-neo4j}
      - NEO4J_PASSWORD=${NEO4J_PASSWORD:-password}
      - INPUT_DATA_PATH=/input_data
      - POETRY_VIRTUALENVS_CREATE=false
      - NEO4J_dbms_directories_import=/neo4j_import
    volumes:
      - neo4j_import:/neo4j_import
      - ${INPUT_DATA_PATH:-./data}:/input_data
      - ./importData:/importData  # Share the import data directory
#    depends_on:
#      neo4j:
#        condition: service_healthy

# Define named volumes
volumes:
  neo4j_data:
  neo4j_logs:
  neo4j_import:
