#!/usr/bin/env bash
set -euo pipefail

repo_root="$(git rev-parse --show-toplevel)"
cd "${repo_root}"

mapfile -t staged_files < <(git diff --cached --name-only --diff-filter=ACMR)
if [[ ${#staged_files[@]} -eq 0 ]]; then
  exit 0
fi

run_backend=false
run_frontend=false

for file in "${staged_files[@]}"; do
  case "${file}" in
    app.py|supertonic_gateway.py|voice_rtc.py|wisper.py|requirements.txt|.ruff.toml|scripts/check_python_quality.sh)
      run_backend=true
      ;;
    frontend/*|scripts/check_frontend_quality.sh)
      run_frontend=true
      ;;
  esac
done

if [[ "${run_backend}" == "true" ]]; then
  echo "Running backend Python checks..."
  ./scripts/check_python_quality.sh
fi

if [[ "${run_frontend}" == "true" ]]; then
  echo "Running frontend checks..."
  ./scripts/check_frontend_quality.sh
fi
