import { NextResponse } from 'next/server' // Import the 24/7 automation service let automation24x7 try { const automationModule = require('../../../../start-24-7-automation.js') automation24x7 = automationModule.automation24x7 } catch (error) { console.error('❌ Could not load 24/7 automation service:', error.message) } export async function POST(request) { try { if (!automation24x7) { return NextResponse.json({ success: false, message: '24/7 automation service not available' }, { status: 500 }) } const { action, config } = await request.json() if (action === 'start') { // Update config if provided if (config) { Object.assign(automation24x7.config, config) } const result = await automation24x7.start() return NextResponse.json(result) } else if (action === 'stop') { const result = await automation24x7.stop() return NextResponse.json(result) } else { return NextResponse.json({ success: false, message: 'Invalid action. Use "start" or "stop"' }, { status: 400 }) } } catch (error) { console.error('❌ 24/7 automation control error:', error) return NextResponse.json({ success: false, message: 'Failed to control automation', error: error.message }, { status: 500 }) } } export async function GET(request) { try { if (!automation24x7) { return NextResponse.json({ success: false, message: '24/7 automation service not available' }, { status: 500 }) } const status = automation24x7.getStatus() return NextResponse.json({ success: true, automation: status }) } catch (error) { console.error('❌ 24/7 automation status error:', error) return NextResponse.json({ success: false, message: 'Failed to get automation status', error: error.message }, { status: 500 }) } }