#!/bin/bash
# MyRoadTrip V2 - Structure Verification Script

set -e

echo "🔍 MyRoadTrip - Verifying Foundation Structure"
echo "==============================================="
echo ""

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

check_file() {
  if [ -f "$1" ]; then
    echo -e "${GREEN}✓${NC} $1"
    return 0
  else
    echo -e "${RED}✗${NC} $1 (missing)"
    return 1
  fi
}

check_dir() {
  if [ -d "$1" ]; then
    echo -e "${GREEN}✓${NC} $1/"
    return 0
  else
    echo -e "${RED}✗${NC} $1/ (missing)"
    return 1
  fi
}

ERRORS=0

echo "📁 Root Configuration"
check_file "turbo.json" || ((ERRORS++))
check_file "pnpm-workspace.yaml" || ((ERRORS++))
check_file "tsconfig.json" || ((ERRORS++))
check_file ".env.example" || ((ERRORS++))
check_file "README.md" || ((ERRORS++))
echo ""

echo "🌐 Frontend (apps/web)"
check_dir "apps/web" || ((ERRORS++))
check_file "apps/web/package.json" || ((ERRORS++))
check_file "apps/web/vite.config.ts" || ((ERRORS++))
check_file "apps/web/tsconfig.json" || ((ERRORS++))
check_file "apps/web/index.html" || ((ERRORS++))
check_file "apps/web/src/app/main.ts" || ((ERRORS++))
check_file "apps/web/src/app/router.ts" || ((ERRORS++))
check_file "apps/web/src/app/App.vue" || ((ERRORS++))
check_file "apps/web/src/modules/auth/stores/authStore.ts" || ((ERRORS++))
check_file "apps/web/src/modules/auth/pages/LoginPage.vue" || ((ERRORS++))
check_file "apps/web/src/modules/planner/pages/HomePage.vue" || ((ERRORS++))
check_file "apps/web/src/modules/planner/pages/PlansListPage.vue" || ((ERRORS++))
check_file "apps/web/src/modules/planner/pages/PlanViewPage.vue" || ((ERRORS++))
echo ""

echo "⚙️  Backend (apps/api)"
check_dir "apps/api" || ((ERRORS++))
check_file "apps/api/package.json" || ((ERRORS++))
check_file "apps/api/tsconfig.json" || ((ERRORS++))
check_file "apps/api/src/server.ts" || ((ERRORS++))
check_file "apps/api/src/core/database/firebase.ts" || ((ERRORS++))
check_file "apps/api/src/core/database/redis.ts" || ((ERRORS++))
check_file "apps/api/src/core/modules.ts" || ((ERRORS++))
check_file "apps/api/src/modules/planner/planner.module.ts" || ((ERRORS++))
check_file "apps/api/src/modules/ai/ai.module.ts" || ((ERRORS++))
check_file "apps/api/src/modules/collab/collab.module.ts" || ((ERRORS++))
check_file "apps/api/src/modules/gamification/gamification.module.ts" || ((ERRORS++))
echo ""

echo "📦 Shared Packages"
check_dir "packages/types" || ((ERRORS++))
check_file "packages/types/package.json" || ((ERRORS++))
check_file "packages/types/src/index.ts" || ((ERRORS++))
check_dir "packages/validators" || ((ERRORS++))
check_file "packages/validators/package.json" || ((ERRORS++))
check_file "packages/validators/src/index.ts" || ((ERRORS++))
check_dir "packages/utils" || ((ERRORS++))
check_file "packages/utils/package.json" || ((ERRORS++))
check_file "packages/utils/src/index.ts" || ((ERRORS++))
check_file "packages/utils/src/geo.ts" || ((ERRORS++))
check_file "packages/utils/src/date.ts" || ((ERRORS++))
check_file "packages/utils/src/string.ts" || ((ERRORS++))
echo ""

echo "📚 Documentation"
check_file "docs/REFERENCE.md" || ((ERRORS++))
check_file "docs/SETUP.md" || ((ERRORS++))
echo ""

echo "=================================================="
if [ $ERRORS -eq 0 ]; then
  echo -e "${GREEN}✅ All checks passed! Foundation is complete.${NC}"
  echo ""
  echo "Next steps:"
  echo "1. Copy .env.example to .env and fill in your credentials"
  echo "2. Run: pnpm install"
  echo "3. Run: pnpm dev"
  echo "4. Proceed to Prompt #2 for feature implementation"
  exit 0
else
  echo -e "${RED}❌ $ERRORS errors found. Please fix missing files/directories.${NC}"
  exit 1
fi
