#!/bin/bash

# Add createId import and IDs to audit_logs.create() calls

FILES=(
  "app/api/auth/verify-signup-otp/route.ts"
  "app/api/auth/verify-login-otp/route.ts"
  "app/api/auth/verify-otp-and-activate/route.ts"
  "app/api/auth/session-from-otp/route.ts"
  "app/api/auth/reset-password/route.ts"
  "app/api/auth/forgot-password/route.ts"
  "app/api/auth/verify-email-only/route.ts"
  "app/api/billing/change-plan/route.ts"
  "app/api/signup/company-info/route.ts"
  "app/api/onboarding/company-info/route.ts"
)

echo "🔧 Adding missing IDs to audit_logs.create() calls"
echo ""

for file in "${FILES[@]}"; do
  if [ ! -f "$file" ]; then
    echo "⏭️  Skipping $file (not found)"
    continue
  fi

  echo "📄 Processing: $file"

  # Check if needs createId import
  if ! grep -q "createId" "$file"; then
    # Add import after other imports
    sed -i.bak "/^import.*from '@\/lib\/db';/a\\
import { createId } from '@paralleldrive/cuid2';
" "$file"
    echo "   ✅ Added createId import"
  fi

  # Note: ID addition needs manual review per file structure
  echo "   ⚠️  Manual ID addition required - check audit_logs.create() calls"
done

echo ""
echo "✅ Imports added - manual review needed for ID insertion"
echo "   Run: grep -n 'audit_logs.create' app/api/auth/*.ts"
