#!/bin/bash
echo "=== WeTransp Full API Dump ==="
echo "Started: $(date)"
outdir="/tmp/wetransp-dump"
mkdir -p "$outdir"

base="https://api.wetransp.com"

# Dump all endpoints from self-documenting root
endpoints=(
  "/v1/province"
  "/v1/municipality"
  "/v1/locality"
  "/v1/via"
  "/v1/type-stop"
  "/v1/type-place"
  "/v1/place"
  "/v1/segment"
  "/v1/route"
  "/v1/route-segment"
  "/v1/bus-stop"
  "/v1/frequency"
  "/v1/schedule"
  "/v1/schedule-bus-stop"
  "/v1/itinerary"
  "/v1/agency"
  "/v1/rol"
  "/v1/permission"
  "/v1/rol-permission"
  "/v1/person"
  "/v1/permission-person"
  "/v1/pin"
  "/v1/help"
  "/v1/version"
)

for ep in "${endpoints[@]}"; do
  fname=$(echo "$ep" | sed 's/\/v1\///' | sed 's/\//-/g')
  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"
  if [ "$size" -lt 200 ] && echo "$result" | grep -qi "auth\|error"; then
    echo "  [AUTH REQUIRED]"
  fi
done

# Also check help pages
for ep in "/v1/province-help" "/v1/locality-help" "/v1/bus-stop-help" "/v1/route-help" "/v1/schedule-help" "/v1/place-help" "/v1/segment-help" "/v1/frequency-help" "/v1/itinerary-help" "/v1/agency-help"; do
  fname=$(echo "$ep" | sed 's/\/v1\///' | sed 's/\//-/g')
  result=$(proxychains4 -q curl -ks --connect-timeout 10 -m 20 "${base}${ep}" 2>/dev/null)
  size=${#result}
  if [ "$size" -gt 100 ]; then
    echo "  Help: $ep ($size bytes)"
    echo "$result" > "${outdir}/${fname}.json"
  fi
done

echo ""
echo "=== FeriasCuba Transfer Dump ==="
fbase="https://apitransfer.feriascuba.com"
for ep in "/v1/province" "/v1/municipality" "/v1/payment" "/v1/place" "/v1/route-travel" "/v1/reservation-private" "/v1/payment-reservation-private" "/v1/version" "/v1/help"; do
  fname=$(echo "$ep" | sed 's/\/v1\//ferias-/' | sed 's/\//-/g')
  echo "Fetching $ep..."
  result=$(proxychains4 -q curl -ks --connect-timeout 15 -m 60 "${fbase}${ep}" 2>/dev/null)
  size=${#result}
  echo "  Size: $size bytes"
  echo "$result" > "${outdir}/${fname}.json"
done

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

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