#!/usr/bin/env bash

set -euo pipefail

if [[ "${1:-}" == "--name" ]]; then
  echo "Mint"
  exit 0
fi

benchmark=""
category=""
order="Linear LPO MaxPlus StdMat(2) SPO(Model(Finite)) RPLex(WPO(MaxPlus),StdMat(2)) SPO(RTLex(Mark(MaxPlus),Mark(Linear))) LexMat(3) SPO(Model(LexMat(3)))"

while [[ $# -gt 0 ]]; do
  case "$1" in
    --timeout=*)
      shift
      ;;
    --timeout)
      shift
      if [[ $# -gt 0 ]]; then
        shift
      fi
      ;;
    --category=*)
      category="${1#*=}"
      shift
      ;;
    --category)
      shift
      if [[ $# -gt 0 ]]; then
        category="$1"
        shift
      fi
      ;;
    --help|-h)
      cat <<'EOF'
Usage:
  solver --name
  solver [--timeout=SECONDS] [--category=CATEGORY] BENCHMARK
EOF
      exit 0
      ;;
    --*)
      echo "solver: unknown option: $1" >&2
      exit 2
      ;;
    *)
      benchmark="$1"
      shift
      if [[ $# -gt 0 ]]; then
        echo "solver: unexpected extra arguments: $*" >&2
        exit 2
      fi
      ;;
  esac
done

if [[ -z "$benchmark" ]]; then
  echo "solver: missing benchmark path" >&2
  exit 2
fi

case "$category" in
  SRS_Standard|SRS_Relative)
    order="Linear MaxPlus LexMat(2) StdMat(2) LexMat(3) StdMat(3) RPLex(StdMat(2),StdMat(2)) LexMat(4) StdMat(4)"
    ;;
  *)
    ;;
esac

exec mint -o "$order" "$benchmark"
