import express from "express";
import {
  createOracSnap,
  updateOracSnap,
  deleteOracSnap,
  serveSnapImage,
  listOracSnaps,
  getOracSnapRecord
} from "../controllers/oracSnapsController.js";

const router = express.Router();
const primaryKeys = ["snap_id", "assessment_id"];
const pkPath = primaryKeys.map((k) => `:${k}`).join("/");

const snapsRouter = express.Router();
snapsRouter.get("/", listOracSnaps);
snapsRouter.get(`/${pkPath}/image`, serveSnapImage);   // serve raw JPEG bytes from DB
snapsRouter.get(`/${pkPath}`, getOracSnapRecord);
snapsRouter.post("/", createOracSnap);
snapsRouter.put(`/${pkPath}`, updateOracSnap);
snapsRouter.delete(`/${pkPath}`, deleteOracSnap);

router.use("/orac_snaps", snapsRouter);

export default router;
