#!/usr/bin/env bash
set -euo pipefail

if ! command -v python3 >/dev/null 2>&1; then
  echo "python3 is required to install the Argus CLI" >&2
  exit 1
fi

wheel_dir="$(mktemp -d)"
wheel_path="$wheel_dir/argus-1.1.9-1725f23fe5d64-py3-none-any.whl"
trap 'rm -rf "$wheel_dir"' EXIT
curl -fsSL https://api.argusfa.com/artifacts/cli/argus-1.1.9-1725f23fe5d64-py3-none-any.whl -o "$wheel_path"
python3 - "$wheel_path" "725f23fe5d649afc071311f3a6a75b6a5be69080f4a85631d2d057fee1eee7f5" <<'PY'
import hashlib
import sys
from pathlib import Path

wheel_path = Path(sys.argv[1])
expected_hash = sys.argv[2]
if hashlib.sha256(wheel_path.read_bytes()).hexdigest() != expected_hash:
    raise SystemExit("Argus CLI wheel SHA-256 verification failed.")
PY
# Resolve missing or incompatible dependencies without forcibly replacing the
# host environment's dependency closure, then refresh only the Argus wheel.
python3 -m pip install --user --upgrade --upgrade-strategy only-if-needed "$wheel_path"
python3 -m pip install --user --force-reinstall --no-deps "$wheel_path"

echo "Argus CLI 1.1.9 installed."
echo "Interactive sign-in:"
echo "  argus auth login"
echo "Then run a remote command:"
echo "  argus company-fact-snapshot --company-id company:example-inc"
echo "Machine clients may instead set ARGUS_BASE_URL and ARGUS_MACHINE_API_KEY."
