if ! command -v javac >/dev/null 2>&1; then
    echo "Error: javac is not installed."
    exit 1
fi

if ! command -v java >/dev/null 2>&1; then
    echo "Error: java is not installed."
    exit 1
fi

find src -name "*.java" > sources.txt
echo "Main.java" >> sources.txt
if ! javac -d build -cp "./extern/sqlite-jdbc-3.50.3.0.jar" @sources.txt Main.java; then
    echo "Error: javac failed to compile sources."
    exit 1
fi
rm sources.txt

if [ ! -d "instance" ]; then
    mkdir instance
fi

java -cp "build:./extern/sqlite-jdbc-3.50.3.0.jar" Main
