import express from "express";
import {
  listRecords,
  getRecordByPk,
  updateRecordByPk,
  deleteRecordByPk
} from "../controllers/genericCrudController.js";
import {
  getSectionWithQuestions,
  createSectionQuestionMap
} from "../controllers/oracSectionQuestionMapController.js";

const router = express.Router();
const mapRouter = express.Router();
const tableName = "orac_section_question_map";
const primaryKeys = ["section_id", "question_id"];

mapRouter.get("/", listRecords(tableName));
mapRouter.get("/section/:section_id", getSectionWithQuestions);
mapRouter.get("/:section_id/:question_id", getRecordByPk(tableName, primaryKeys));
mapRouter.post("/", createSectionQuestionMap);
mapRouter.put("/:section_id/:question_id", updateRecordByPk(tableName, primaryKeys));
mapRouter.delete("/:section_id/:question_id", deleteRecordByPk(tableName, primaryKeys));

// Keep legacy typo path for compatibility with existing clients.
router.use("/orac_section_question_map", mapRouter);
router.use("/orac_section_question_map", mapRouter);

export default router;

