import { Router } from 'express';
import { listSchedules, replaceSchedules } from '../scheduler.js';

export const schedulesRouter = Router();

schedulesRouter.get('/', (_req, res) => {
  res.json(listSchedules());
});

schedulesRouter.put('/', async (req, res, next) => {
  try {
    const schedules = await replaceSchedules(req.body?.schedules || []);
    res.json(schedules);
  } catch (error) {
    next(error);
  }
});
