#!/bin/sh
set -eu

project_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
dotnet_command=${PROJECTQUINT_DOTNET:-dotnet}
if ! command -v "$dotnet_command" >/dev/null 2>&1; then
    echo "Install the .NET 10 SDK or set PROJECTQUINT_DOTNET to its executable." >&2
    exit 127
fi
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1
cd "$project_root/Verification"

if [ "${1:-}" = test ]; then
    shift
    exec "$dotnet_command" test ProjectQuint.Tests/ProjectQuint.Tests.csproj \
        --configuration Release -p:RestoreLockedMode=true "$@"
fi

# Keep build diagnostics on stderr so replay/benchmark stdout is exactly one JSON document.
"$dotnet_command" build ProjectQuint.Agent/ProjectQuint.Agent.csproj \
    --configuration Release --verbosity quiet >&2
exec "$dotnet_command" ProjectQuint.Agent/bin/Release/net10.0/ProjectQuint.Agent.dll "$@"
