#!/bin/bash
set -euo pipefail

data_rel="$1"
jar_path="$2"

# Get version line
output="$(java -jar "$jar_path")"

# Expect format: FWD v4.0.0_p2j_<branch>_<revision>
if [[ ! "$output" =~ _p2j_([^_]+)_([0-9]+) ]]; then
   echo "ERROR: Unable to parse p2j output: $output" >&2
   exit 1
fi

branch="${BASH_REMATCH[1]}"
revision="${BASH_REMATCH[2]}"

use_post=false

# ---- Policy Rules ----
if [[ "$branch" == "trunk" && "$revision" -ge 16415 ]]; then
   use_post=true
fi

# Future policy example
#if [[ "$branch" == "9986c" && "$revision" -ge 16300 ]]; then
#   use_post=true
#fi
# ----------------------

if $use_post; then
   echo post9950
   exit 0
fi

# Fallback handling for pre9950
if [[ ! -f "$data_rel/standard_pre9950.df" && -f "$data_rel/standard.df" ]]; then
   echo skip
   exit 0
fi

echo pre9950
