#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
echo '[1/5] PHP syntax checks'
find app bootstrap config database routes tests -name '*.php' -print0 | while IFS= read -r -d '' file; do php -l "$file" >/dev/null; done
echo 'PHP syntax: PASS'
echo '[2/5] JavaScript syntax checks'
if command -v node >/dev/null 2>&1; then
  find public -name '*.js' -print0 | while IFS= read -r -d '' file; do node --check "$file"; done
  echo 'JavaScript syntax: PASS'
else
  echo 'Node.js unavailable: SKIPPED'
fi
echo '[3/5] Composer validation'
if command -v composer >/dev/null 2>&1; then composer validate --no-check-publish
else echo 'Composer unavailable: SKIPPED'; fi
echo '[4/5] Laravel tests'
if [[ -f vendor/autoload.php ]]; then
  if php -m | grep -qi '^pdo_sqlite$'; then php artisan test
  else echo 'PDO SQLite driver is unavailable for the configured in-memory test database: SKIPPED'; fi
else echo 'Composer dependencies are not installed: SKIPPED'; fi
echo '[5/5] Required files'
test -f .env.example
test -f database/migrations/2026_01_01_000007_create_interoperability_sync.php
test -f public/index.php
test -f public/service-worker.js
test -f Dockerfile
test -f docker-compose.yml
test -f documentation/DOCKER_DEPLOYMENT.md
 test -f app/Console/Commands/CreateSuperAdministrator.php
 test -f tests/TestCase.php
 test -f tests/Feature/SystemReadinessAcceptanceTest.php
 test -f tests/Feature/ApiRateLimitAcceptanceTest.php
 test -f scripts/phase20-acceptance.sh
 test -f documentation/PHASE20_ACCEPTANCE_MATRIX.md
test -f documentation/INSTALLATION_GUIDE.md
echo 'Project preflight: PASS (runtime tests may be skipped when dependencies are absent)'
