import { emergencyAutomation } from '@/lib/emergency-automation'

export async function POST() {
  try {
    console.log('🚨 EMERGENCY: Stop request received')
    
    const result = await emergencyAutomation.stop()
    
    // Also force kill any remaining processes
    try {
      const { execSync } = require('child_process')
      execSync('pkill -f "chrome|chromium" 2>/dev/null || true')
      console.log('✅ EMERGENCY: Cleanup completed')
    } catch (cleanupError) {
      console.error('Cleanup error:', cleanupError.message)
    }
    
    return Response.json(result)
  } catch (error) {
    return Response.json({
      success: false,
      message: error.message
    }, { status: 500 })
  }
}
