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

async function handler(req, res) {
  try {
    const { deviceId } = req.query;
    let schedules;
    if (deviceId && typeof deviceId === "string") {
      schedules = await db.select().from(backupSchedules).where(eq(backupSchedules.deviceId, deviceId));
    } else {
      schedules = await db.select().from(backupSchedules);
    }
    res.status(200).json({
      success: true,
      schedules,
      count: schedules.length
    });
  } catch (error) {
    console.error("Failed to fetch schedules:", error);
    res.status(500).json({
      success: false,
      error: "Failed to fetch schedules",
      message: String(error)
    });
  }
}

export { handler as h };
