import { d as db, c as devices, b as backups } from '../../admin/create-upload-progress-table/POST-C-OoiMoW.js';
import { eq, desc } 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 device = await db.select().from(devices).where(eq(devices.deviceId, deviceId)).limit(1);
    if (device.length === 0) {
      return res.status(404).json({
        success: false,
        error: "Device not found"
      });
    }
    const recentBackups = await db.select().from(backups).where(eq(backups.deviceId, device[0].id)).orderBy(desc(backups.createdAt)).limit(10);
    res.json({
      success: true,
      device: device[0],
      recentBackups
    });
  } catch (error) {
    console.error("Device fetch error:", error);
    res.status(500).json({
      success: false,
      error: "Failed to fetch device",
      message: String(error)
    });
  }
}

export { handler as h };
