import express from "express";
import { createCrudRouter } from "./crudRouter.js";
import {
  listTickets,
  getTicket,
  createTicket,
  updateTicket,
  deleteTicket
} from "../controllers/ticketsController.js";

const router = express.Router();

// Tickets: dedicated controller so updates/deletes snapshot into tickets_logs.
router.get("/tickets", listTickets);
router.get("/tickets/:id", getTicket);
router.post("/tickets", createTicket);
router.put("/tickets/:id", updateTicket);
router.delete("/tickets/:id", deleteTicket);

// Read access to the immutable audit trail.
router.use("/tickets_logs", createCrudRouter("tickets_logs", ["id"]));

export default router;
