#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."

python3 scripts/static_verify.py
node --check vite.config.js
node --check resources/js/app.js

if [[ "${STATIC_ONLY:-0}" == "1" ]]; then
  printf 'Static-only verification passed.\n'
  exit 0
fi

if ! command -v composer >/dev/null 2>&1; then
  printf 'Composer is required for full verification. Run STATIC_ONLY=1 ./scripts/verify.sh for structural checks only.\n' >&2
  exit 2
fi

composer validate
composer install --no-interaction --prefer-dist
php artisan optimize:clear
php artisan test
php artisan accounting:integrity-check

if command -v npm >/dev/null 2>&1; then
  npm ci --no-audit --no-fund
  npm run build
fi

printf 'Full application verification passed.\n'
