import express from "express";
import {
  listRecords,
  getRecordByPk,
  updateRecordByPk,
  deleteRecordByPk
} from "../controllers/genericCrudController.js";
import {
  getFormIdForLocation,
  getDefaultFormId,
  getFormWithSectionsAndQuestions,
  createFormSectionMap
} from "../controllers/oracFormSectionMapController.js";

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

mapRouter.get("/", listRecords(tableName));
mapRouter.get("/default-form-id", getDefaultFormId);
mapRouter.get("/by-location/:location_id", getFormIdForLocation);
mapRouter.get("/form/:form_id", getFormWithSectionsAndQuestions);
mapRouter.get("/:form_id/:section_id", getRecordByPk(tableName, primaryKeys));
mapRouter.post("/", createFormSectionMap);
mapRouter.put("/:form_id/:section_id", updateRecordByPk(tableName, primaryKeys));
mapRouter.delete("/:form_id/:section_id", deleteRecordByPk(tableName, primaryKeys));

router.use("/orac_form_section_map", mapRouter);

export default router;
