#!/usr/bin/env bash
# Fetch the nym-client binary required for the embedded build.
# The binary is not committed to keep the repository small.
#
# Target: nym-client v1.1.76 (linux/amd64), the version NymDrop is tested with.
set -euo pipefail

VERSION="v1.1.76"
URL="https://github.com/nymtech/nym/releases/download/nym-binaries-${VERSION}/nym-client"
DEST_DIRS=(
  "cmd/nymdrop/bin"
  "internal/reader/bin"
)

root="$(cd "$(dirname "$0")/.." && pwd)"
tmp="$(mktemp)"
echo "Downloading nym-client ${VERSION} ..."
curl -fL "$URL" -o "$tmp"
chmod +x "$tmp"

for d in "${DEST_DIRS[@]}"; do
  mkdir -p "$root/$d"
  cp "$tmp" "$root/$d/nym-client-linux-amd64"
  echo "  installed -> $d/nym-client-linux-amd64"
done
rm -f "$tmp"
echo "Done. You can now run: go build ./cmd/nymdrop/ && go build ./cmd/nymdrop-reader/"
