import { NextResponse } from 'next/server' import { automationService } from '@/lib/automation-service-simple' import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() export async function POST() { try { // Stop the automation service const success = await automationService.stopAutomation() // Also update all active automation sessions in database to INACTIVE await prisma.automationSession.updateMany({ where: { status: 'ACTIVE' }, data: { status: 'INACTIVE', updatedAt: new Date() } }) console.log('🛑 All automation sessions marked as INACTIVE in database') if (success) { return NextResponse.json({ success: true, message: 'Automation stopped successfully' }) } else { return NextResponse.json({ success: false, error: 'Failed to stop automation' }, { status: 500 }) } } catch (error) { console.error('Stop automation error:', error) return NextResponse.json({ success: false, error: 'Internal server error', message: error.message }, { status: 500 }) } }