#!/usr/bin/env bash
set -eux
pushd "$(dirname "$0")"

CHESSCOACH_DATA="${XDG_DATA_HOME-$HOME/.local/share}/ChessCoach"
CHESSCOACH_DATA_ZIP="${CHESSCOACH_DATA}/Data.zip"

CHESSCOACH_GAMES_SUPERVISED="${CHESSCOACH_DATA}/Games/Supervised"
CHESSCOACH_GAMES_VALIDATION="${CHESSCOACH_DATA}/Games/Validation"
CHESSCOACH_DATA_DATA="${CHESSCOACH_DATA}/Data"
CHESSCOACH_VALIDATION_DATA_CCRL="${CHESSCOACH_DATA_DATA}/cclr"
CHESSCOACH_VALIDATION_DATA_CCRL_TRAINING="${CHESSCOACH_VALIDATION_DATA_CCRL}/train"
CHESSCOACH_VALIDATION_DATA_CCRL_VALIDATION="${CHESSCOACH_VALIDATION_DATA_CCRL}/test"

mkdir -p "${CHESSCOACH_GAMES_SUPERVISED}"
mkdir -p "${CHESSCOACH_GAMES_VALIDATION}"
mkdir -p "${CHESSCOACH_DATA_DATA}"

curl -L https://storage.lczero.org/files/ccrl-pgn.tar.bz2 | tar -xj -C "${CHESSCOACH_DATA_DATA}"

ChessCoachPgnToGames -i "${CHESSCOACH_VALIDATION_DATA_CCRL_TRAINING}" -o "${CHESSCOACH_GAMES_SUPERVISED}"
ChessCoachPgnToGames -i "${CHESSCOACH_VALIDATION_DATA_CCRL_VALIDATION}" -o "${CHESSCOACH_GAMES_VALIDATION}"

rm -r "${CHESSCOACH_VALIDATION_DATA_CCRL}"

popd