#!/bin/bash
echo "=== Banco Central Full API Dump ==="
echo "Started: $(date)"

base="https://api.bc.gob.cu/v1"
outdir="/tmp/bc-dump"
mkdir -p "$outdir"

# All known endpoints
endpoints=(
  "/exchange-rate"
  "/exchange-rate/previous"
  "/branches"
  "/banks"
  "/statistics"
  "/news"
  "/legal"
  "/ict-statistics"
  "/about"
  "/contact"
  "/faq"
  "/glossary"
  "/branches?limit=1000"
  "/exchange-rate?limit=100"
  "/news?limit=100"
  "/legal?limit=100"
  "/statistics?limit=100"
)

for ep in "${endpoints[@]}"; do
  fname=$(echo "$ep" | sed 's/[?=&\/]/_/g' | sed 's/^_//')
  echo "Fetching $ep..."
  result=$(proxychains4 -q curl -ks --connect-timeout 15 -m 60 "${base}${ep}" 2>/dev/null)
  size=${#result}
  echo "  Size: $size bytes"
  echo "$result" > "${outdir}/${fname}.json"
done

# Also try these
for ep in "/exchange-rate/latest" "/exchange-rate/history" "/branches/bfi" "/banks/1" "/banks/2" "/banks/3" "/banks/4" "/banks/5" "/statistics/ict" "/auth/login" "/auth/register" "/users" "/swagger" "/docs"; do
  fname=$(echo "$ep" | sed 's/[?=&\/]/_/g' | sed 's/^_//')
  code=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}" --connect-timeout 10 -m 20 "${base}${ep}" 2>/dev/null)
  echo "  [$code] $ep"
  if [ "$code" = "200" ]; then
    proxychains4 -q curl -ks --connect-timeout 10 -m 30 "${base}${ep}" > "${outdir}/${fname}.json" 2>/dev/null
    echo "    Saved $(wc -c < "${outdir}/${fname}.json") bytes"
  fi
done

echo ""
echo "=== File listing ==="
ls -la "$outdir/"

echo ""
echo "Completed: $(date)"
