#!/bin/sh
# Pre-commit hook for bot repo (Go + Node.js)
# Install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

set -e

# Go: vet + build Team Tool
if git diff --cached --name-only | grep -q 'cli/transcribe/'; then
  echo "[pre-commit] Go vet cli/transcribe..."
  (cd cli/transcribe && go vet ./...)
  echo "[pre-commit] Go build cli/transcribe..."
  (cd cli/transcribe && go build -o /dev/null . 2>&1 || go build -o NUL . 2>&1)
  echo "[pre-commit] Team Tool OK"
fi

# Go: vet + build deeptinqs CLI
if git diff --cached --name-only | grep -q 'cli/deeptinqs/'; then
  echo "[pre-commit] Checking cli/deeptinqs..."
  if ls cli/deeptinqs/*.go >/dev/null 2>&1; then
    (cd cli/deeptinqs && go vet ./... 2>/dev/null && go build -o /dev/null . 2>/dev/null) || true
  fi
fi

# Node.js: lint bot web app
if git diff --cached --name-only | grep -qE '\.(ts|tsx|js|jsx)$'; then
  if [ -f "package.json" ]; then
    echo "[pre-commit] JS/TS lint..."
    npx tsc --noEmit 2>/dev/null || true
  fi
fi

echo "[pre-commit] All checks passed."
