#!/bin/bash
# Docker Dashboard Verification Script
# Verifies all new dashboard files are included in Docker build

set -e

echo "🔍 Verifying Docker build includes all dashboard files..."
echo ""

IMAGE="${1:-mawidi-site:latest}"

echo "📦 Using image: $IMAGE"
echo ""

# Check if image exists
if ! docker image inspect $IMAGE &> /dev/null; then
  echo "❌ Image $IMAGE not found. Building now..."
  docker build -t $IMAGE .
fi

echo "1️⃣  Checking API routes..."
docker run --rm $IMAGE ls app/api/conversations/route.ts 2>/dev/null && echo "  ✅ conversations/route.ts" || echo "  ❌ conversations/route.ts MISSING"
docker run --rm $IMAGE ls app/api/bookings/route.ts 2>/dev/null && echo "  ✅ bookings/route.ts" || echo "  ❌ bookings/route.ts MISSING"
docker run --rm $IMAGE ls app/api/analytics/metrics/route.ts 2>/dev/null && echo "  ✅ analytics/metrics/route.ts" || echo "  ❌ analytics/metrics/route.ts MISSING"
docker run --rm $IMAGE ls app/api/notifications/route.ts 2>/dev/null && echo "  ✅ notifications/route.ts" || echo "  ❌ notifications/route.ts MISSING"
docker run --rm $IMAGE ls app/api/integrations/route.ts 2>/dev/null && echo "  ✅ integrations/route.ts" || echo "  ❌ integrations/route.ts MISSING"
echo ""

echo "2️⃣  Checking dashboard components..."
docker run --rm $IMAGE ls app/\[lang\]/dashboard/NewDashboardClient.tsx 2>/dev/null && echo "  ✅ NewDashboardClient.tsx" || echo "  ❌ NewDashboardClient.tsx MISSING"
docker run --rm $IMAGE ls app/\[lang\]/dashboard/components/MetricsOverview.tsx 2>/dev/null && echo "  ✅ MetricsOverview.tsx" || echo "  ❌ MetricsOverview.tsx MISSING"
docker run --rm $IMAGE ls app/\[lang\]/dashboard/components/NotificationBell.tsx 2>/dev/null && echo "  ✅ NotificationBell.tsx" || echo "  ❌ NotificationBell.tsx MISSING"
docker run --rm $IMAGE ls app/\[lang\]/dashboard/components/WhatsAppPanel.tsx 2>/dev/null && echo "  ✅ WhatsAppPanel.tsx" || echo "  ❌ WhatsAppPanel.tsx MISSING"
docker run --rm $IMAGE ls app/\[lang\]/dashboard/components/AppointmentsList.tsx 2>/dev/null && echo "  ✅ AppointmentsList.tsx" || echo "  ❌ AppointmentsList.tsx MISSING"
echo ""

echo "3️⃣  Checking translation modules..."
docker run --rm $IMAGE ls lib/config/translations/modules/dashboard.en.ts 2>/dev/null && echo "  ✅ dashboard.en.ts" || echo "  ❌ dashboard.en.ts MISSING"
docker run --rm $IMAGE ls lib/config/translations/modules/dashboard.ar.ts 2>/dev/null && echo "  ✅ dashboard.ar.ts" || echo "  ❌ dashboard.ar.ts MISSING"
echo ""

echo "4️⃣  Checking Prisma schema updates..."
docker run --rm $IMAGE grep -q "model WhatsAppConversation" prisma/schema.prisma 2>/dev/null && echo "  ✅ WhatsAppConversation model" || echo "  ❌ WhatsAppConversation model MISSING"
docker run --rm $IMAGE grep -q "model Booking" prisma/schema.prisma 2>/dev/null && echo "  ✅ Booking model" || echo "  ❌ Booking model MISSING"
docker run --rm $IMAGE grep -q "model Notification" prisma/schema.prisma 2>/dev/null && echo "  ✅ Notification model" || echo "  ❌ Notification model MISSING"
docker run --rm $IMAGE grep -q "model Integration" prisma/schema.prisma 2>/dev/null && echo "  ✅ Integration model" || echo "  ❌ Integration model MISSING"
echo ""

echo "5️⃣  Checking Prisma client generation..."
docker run --rm $IMAGE ls lib/generated/prisma/index.js 2>/dev/null && echo "  ✅ Prisma client generated" || echo "  ❌ Prisma client NOT generated"
echo ""

echo "✅ Docker verification complete!"
echo ""
echo "Next steps:"
echo "1. Run migration: npx prisma migrate dev --name add_dashboard_features"
echo "2. Start services: docker-compose --profile development up -d"
echo "3. Access dashboard: http://localhost:9000/en/dashboard"
