#!/bin/bash
# Pre-warm matches_date_get cache for all APIs (yesterday, today, tomorrow).
# Suggested cron: 55 18 * * * /home/ysscores/public_html/scripts/prewarm_matches_date_get.sh

set -euo pipefail

APIS=(api-ar api-en api-es api-fr)
EMPTY="%5B%5D"
DATES=(
  "$(date -d '-1 day' +%Y-%m-%d 2>/dev/null || date -v-1d +%Y-%m-%d)"
  "$(date +%Y-%m-%d)"
  "$(date -d '+1 day' +%Y-%m-%d 2>/dev/null || date -v+1d +%Y-%m-%d)"
)

for api in "${APIS[@]}"; do
  for date in "${DATES[@]}"; do
    curl -sS -o /dev/null -H "Cache-Control: no-cache" \
      "https://${api}.ysscores.com/api/matches/matches_date_get/${date}/${EMPTY}/${EMPTY}/${EMPTY}/L/180" &
  done
done

wait
