import { Router } from "express";
import { authenticate } from "../controllers";
import { CaldavController } from "../controllers/CaldavController";

export function createCaldavRoutes(caldavController: CaldavController): Router {
  const router = Router();

  router.use(authenticate);

  router.put("/config", (req, res) => caldavController.saveConfig(req, res));
  router.get("/config", (req, res) => caldavController.loadConfig(req, res));
  router.delete("/config", (req, res) =>
    caldavController.deleteConfig(req, res),
  );
  router.post("/pull", (req, res) => caldavController.pullEvents(req, res));
  router.post("/pushAll", (req, res) => caldavController.pushEvents(req, res));
  router.post("/push/:caldavUUID", (req, res) =>
    caldavController.pushEvent(req, res),
  );

  return router;
}
