#!/bin/bash

echo "=== Trip With Us Meta-Agent Setup Verification ==="

# Check directory structure
echo "📁 Checking directory structure..."
directories=(
  "meta-agent/config"
  "meta-agent/state" 
  "meta-agent/templates"
  "meta-agent/scripts"
  "meta-agent/docs"
)

for dir in "${directories[@]}"; do
  if [ -d "$dir" ]; then
    echo "✅ $dir exists"
  else
    echo "❌ $dir missing"
  fi
done

# Check configuration files
echo "📄 Checking configuration files..."
config_files=(
  "meta-agent/config/agent-persona.md"
  "meta-agent/config/project-config.json"
  "meta-agent/config/command-templates.json"
  "meta-agent/state/project-state.json"
)

for file in "${config_files[@]}"; do
  if [ -f "$file" ]; then
    echo "✅ $file exists"
  else
    echo "❌ $file missing"
  fi
done

# Validate JSON files
echo "🔍 Validating JSON configuration..."
json_files=(
  "meta-agent/config/project-config.json"
  "meta-agent/config/command-templates.json"
  "meta-agent/state/project-state.json"
)

for file in "${json_files[@]}"; do
  if [ -f "$file" ]; then
    if jq empty "$file" 2>/dev/null; then
      echo "✅ $file is valid JSON"
    else
      echo "❌ $file has invalid JSON syntax"
    fi
  fi
done

# Check Trip With Us project structure
echo "🏗️ Checking Trip With Us project structure..."
twu_directories=(
  "src/components"
  "src/pages"
  "src/hooks"
  "src/api"
  "src/types"
  "tests"
  "supabase"
)

for dir in "${twu_directories[@]}"; do
  if [ -d "$dir" ]; then
    echo "✅ $dir exists"
  else
    echo "⚠️ $dir missing (may need to be created)"
  fi
done

# Check package.json for required dependencies
echo "📦 Checking key dependencies..."
if [ -f "package.json" ]; then
  if grep -q "react" package.json; then
    echo "✅ React found in package.json"
  else
    echo "❌ React not found in package.json"
  fi
  
  if grep -q "typescript" package.json; then
    echo "✅ TypeScript found in package.json"
  else
    echo "❌ TypeScript not found in package.json"
  fi
  
  if grep -q "@supabase/supabase-js" package.json; then
    echo "✅ Supabase client found in package.json"
  else
    echo "❌ Supabase client not found in package.json"
  fi
else
  echo "❌ package.json not found"
fi

echo ""
echo "=== Setup Verification Complete ==="
echo "If any items are marked with ❌, please address them before proceeding."
echo "Items marked with ⚠️ may be created during development."