// routes/purchaseTermsRoutes.js
const express = require("express");
const router = express.Router();
const purchaseTermsController = require("../../controllers/procurement/TermsController");
const authenticate = require("../../middlewares/authenticate");

// ==================== DETAILED CONTENT (Quill Editor) ====================

// GET detailed content by doc_type
router.get(
  "/detailed/:doc_type",
  authenticate,
  (req, res) => {
    purchaseTermsController.getDetailedContent(req, res);
  }
);

// GET all detailed contents for an org
router.get(
  "/detailed",
  authenticate,
  (req, res) => {
    purchaseTermsController.getAllDetailedContents(req, res);
  }
);

// SAVE/UPDATE detailed content
router.post(
  "/detailed/save",
  authenticate,
  (req, res) => {
    purchaseTermsController.saveDetailedContent(req, res);
  }
);

// DELETE detailed content
router.delete(
  "/detailed/:doc_type",
  authenticate,
  (req, res) => {
    purchaseTermsController.deleteDetailedContent(req, res);
  }
);

// ==================== DOCUMENT TYPES ====================

// GET all document types
router.get(
  "/doc-types",
  authenticate,
  (req, res) => {
    purchaseTermsController.getAllDocumentTypes(req, res);
  }
);

// GET document type by id
router.get(
  "/doc-types/:id",
  authenticate,
  (req, res) => {
    purchaseTermsController.getDocumentTypeById(req, res);
  }
);

// CREATE document type
router.post(
  "/doc-types",
  authenticate,
  (req, res) => {
    purchaseTermsController.createDocumentType(req, res);
  }
);

// UPDATE document type
router.put(
  "/doc-types/:id",
  authenticate,
  (req, res) => {
    purchaseTermsController.updateDocumentType(req, res);
  }
);

// DELETE document type (soft delete)
router.delete(
  "/doc-types/:id",
  authenticate,
  (req, res) => {
    purchaseTermsController.deleteDocumentType(req, res);
  }
);

// ==================== TERM ROWS (for document types) ====================

// GET term rows by doc_type
router.get(
  "/term-rows/:doc_type",
  authenticate,
  (req, res) => {
    purchaseTermsController.getTermRowsByDocType(req, res);
  }
);

// CREATE term row
router.post(
  "/term-rows",
  authenticate,
  (req, res) => {
    purchaseTermsController.createTermRow(req, res);
  }
);

// UPDATE term row
router.put(
  "/term-rows/:id",
  authenticate,
  (req, res) => {
    purchaseTermsController.updateTermRow(req, res);
  }
);

// DELETE term row
router.delete(
  "/term-rows/:id",
  authenticate,
  (req, res) => {
    purchaseTermsController.deleteTermRow(req, res);
  }
);

// BULK update term rows (for reordering)
router.put(
  "/term-rows/bulk",
  authenticate,
  (req, res) => {
    purchaseTermsController.bulkUpdateTermRows(req, res);
  }
);

module.exports = router;