version: "3"
internal: true

vars:
  # Version extraction from Cargo.toml (workspace.package.version)
  VERSION:
    sh: grep -m 1 'version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/'

  # Build profile (dev/release/ci) - default to release
  BUILD_PROFILE: '{{.BUILD_PROFILE | default "release"}}'

  # Kreuzberg-specific versions
  ORT_VERSION: "1.24.1"

  # Toolchain versions
  GOLANGCI_LINT_VERSION: "latest"

  # Logging
  RUST_LOG: "info"

  # Root project directories (absolute paths)
  ROOT: "{{.ROOT_DIR}}"
  CRATES_DIR: "{{.ROOT_DIR}}/crates"
  PACKAGES_DIR: "{{.ROOT_DIR}}/packages"
  SCRIPTS_DIR: "{{.ROOT_DIR}}/scripts"
  TOOLS_DIR: "{{.ROOT_DIR}}/tools"
  TARGET_DIR: "{{.ROOT_DIR}}/target"

  # OS Detection
  OS:
    sh: |
      case "$(uname -s 2>/dev/null || echo 'unknown')" in
        Darwin*)
          echo "darwin"
          ;;
        Linux*)
          echo "linux"
          ;;
        MINGW*|MSYS*|CYGWIN*)
          echo "windows"
          ;;
        *)
          if [[ "$OSTYPE" == "darwin"* ]]; then
            echo "darwin"
          elif [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "linux"* ]]; then
            echo "linux"
          elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
            echo "windows"
          else
            echo "unknown"
          fi
          ;;
      esac

  # OS Boolean helpers
  IS_WINDOWS:
    sh: |
      if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo "true"
      else
        echo "false"
      fi

  IS_MACOS:
    sh: |
      if [[ "$OSTYPE" == "darwin"* ]]; then
        echo "true"
      else
        echo "false"
      fi

  IS_LINUX:
    sh: |
      if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "linux"* ]]; then
        echo "true"
      else
        echo "false"
      fi

  # Architecture detection
  ARCH:
    sh: |
      ARCH=$(uname -m)
      case "$ARCH" in
        x86_64|x64)
          echo "x86_64"
          ;;
        aarch64|arm64)
          echo "arm64"
          ;;
        armv7l|armv7)
          echo "armv7"
          ;;
        armv6l|armv6)
          echo "armv6"
          ;;
        i686|i386)
          echo "i386"
          ;;
        *)
          echo "$ARCH"
          ;;
      esac

  # Number of CPUs available
  NUM_CPUS:
    sh: |
      if command -v nproc >/dev/null 2>&1; then
        nproc
      elif [[ "$OSTYPE" == "darwin"* ]]; then
        sysctl -n hw.ncpu
      elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo "${NUMBER_OF_PROCESSORS:-4}"
      else
        echo "4"
      fi

  MAKE_JOBS: "{{.NUM_CPUS}}"
