import { d as db, r as remoteCommands } from '../../../admin/create-upload-progress-table/POST-C-OoiMoW.js';
import { and, eq } from 'drizzle-orm';

async function handler(req, res) {
  try {
    const { deviceId } = req.params;
    if (!deviceId) {
      return res.status(400).json({
        success: false,
        error: "Device ID is required"
      });
    }
    const commands = await db.select().from(remoteCommands).where(
      and(
        eq(remoteCommands.deviceId, deviceId),
        eq(remoteCommands.status, "pending")
      )
    ).orderBy(remoteCommands.sentAt);
    res.json({
      success: true,
      commands
    });
  } catch (error) {
    console.error("Commands fetch error:", error);
    res.status(500).json({
      success: false,
      error: "Failed to fetch commands",
      message: String(error)
    });
  }
}

export { handler as h };
