#!/bin/sh
# usage: ./check.sh <mc version>
MC="$1"
[ -z "$MC" ] && { echo "usage: $0 <mc version>"; exit 1; }

MODS="
https://modrinth.com/mod/fabric-api
https://modrinth.com/mod/dynamic-fps
https://modrinth.com/mod/cloth-config
https://modrinth.com/mod/better-block-entities
https://modrinth.com/mod/c2me-fabric
https://modrinth.com/mod/entityculling
https://modrinth.com/mod/fast-ip-ping
https://modrinth.com/mod/immediatelyfast
https://modrinth.com/mod/lithium
https://modrinth.com/mod/moreculling
https://modrinth.com/mod/particle-core
https://modrinth.com/mod/fabric-language-kotlin
https://modrinth.com/mod/fzzy-config
https://modrinth.com/mod/scalablelux
https://modrinth.com/mod/sodium
https://modrinth.com/mod/reeses-sodium-options
https://modrinth.com/mod/sodium-extra
https://modrinth.com/mod/appleskin
https://modrinth.com/mod/detail-armor-bar-reconstructed
https://modrinth.com/mod/eclipseui
https://modrinth.com/mod/dynamiccrosshair
https://modrinth.com/mod/held-item-info
https://modrinth.com/mod/inventoryhudplus
https://modrinth.com/mod/jade
https://modrinth.com/mod/litematica
https://modrinth.com/mod/malilib
https://modrinth.com/mod/minihud
https://modrinth.com/mod/torohealth-continued
https://modrinth.com/mod/xaeros-minimap
https://modrinth.com/mod/xaeros-world-map
https://modrinth.com/mod/better-advancements
https://modrinth.com/mod/better-stats
https://modrinth.com/mod/tcdcommons
https://modrinth.com/mod/betterf3
https://modrinth.com/mod/cubes-without-borders
https://modrinth.com/mod/auto-clicker
https://modrinth.com/mod/autoreconnectrf
https://modrinth.com/mod/bobby
https://modrinth.com/mod/cut-through
https://modrinth.com/mod/forge-config-api-port
https://modrinth.com/mod/puzzles-lib
https://modrinth.com/mod/fast-trading
https://modrinth.com/mod/inventory-profiles-next
https://modrinth.com/mod/libipn
https://modrinth.com/mod/lambdynamiclights
https://modrinth.com/mod/tweakeroo
https://modrinth.com/mod/voxy
https://modrinth.com/mod/voxy-extra
https://modrinth.com/plugin/voxy-server-side
https://modrinth.com/mod/zoomify
https://modrinth.com/mod/yacl
https://modrinth.com/mod/3dskinlayers
https://modrinth.com/mod/continuity
https://modrinth.com/mod/dark-loading-screen
https://modrinth.com/mod/fallingleaves
https://modrinth.com/mod/iris
https://modrinth.com/mod/picture-mode
https://modrinth.com/mod/wavey-capes
https://modrinth.com/mod/controlling
https://modrinth.com/mod/searchables
https://modrinth.com/mod/modmenu
https://modrinth.com/mod/respackopts
https://modrinth.com/mod/libjf
"

# pulls the first (newest) value of a JSON field out of $res
field() { echo "$res" | grep -o "\"$1\":\"[^\"]*\"" | head -1 | cut -d'"' -f4; }

for url in $MODS; do
  m="${url##*/}"
  res=$(curl -sG "https://api.modrinth.com/v2/project/$m/version" \
    -H "User-Agent: FatherOfAlways/mc-compat-check" \
    --data-urlencode "game_versions=[\"$MC\"]" \
    --data-urlencode 'loaders=["fabric"]')
  case "$res" in
    "[]")  echo "MISSING  $m" ;;
    "["*)  extra=""
           # comment out any line below to hide that field
           # extra="$extra $(field version_number)"
           # extra="$extra ($(field version_type))"
           echo "OK       $m$extra" ;;
    *)     echo "ERROR    $m  (bad slug, or the request failed)" ;;
  esac
done