import { NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; export async function POST( req: Request, { params }: { params: Promise<{ id: string }> } ) { try { const { id } = await params; const { command } = await req.json(); // In a real implementation, this would communicate with the hardware // For now, we simulate success and update the database accordingly const device = await prisma.device.findUnique({ where: { id } }); if (!device) { return NextResponse.json({ error: "Device not found" }, { status: 404 }); } switch (command) { case "REBOOT": // Simulate reboot logic console.log(`[DEVICE CMD] Rebooting device ${device.serialNumber}`); break; case "SHUTDOWN": // Simulate shutdown logic console.log(`[DEVICE CMD] Shutting down device ${device.serialNumber}`); await prisma.device.update({ where: { id }, data: { status: "OFFLINE" } }); break; default: return NextResponse.json({ error: "Unknown command" }, { status: 400 }); } return NextResponse.json({ success: true, command }); } catch (error) { return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }); } }