const express = require("express");
const router = express.Router();
const termsController = require("../../controllers/procurement/termsController");
const authenticate = require("../../middlewares/authenticate");



// Add these to your router file (after the term rows routes)

// ==================== BASIC TERMS ====================

router.get("/basic", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get all basic terms with pagination'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getBasicTerms(req, res);
});

router.delete("/basic/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Delete basic term'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.deleteBasicTerm(req, res);
});
// ==================== DETAILED CONTENT (Quill Editor) ====================

router.get("/detailed/:doc_type", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get detailed content by document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getDetailedContent(req, res);
});

router.get("/detailed", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get all detailed contents for organization'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getAllDetailedContents(req, res);
});

router.post("/detailed/save", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Save or update detailed content'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.saveDetailedContent(req, res);
});

router.delete("/detailed/:doc_type", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Delete detailed content'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.deleteDetailedContent(req, res);
});

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

router.get("/doc-types", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get all document types'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getAllDocumentTypes(req, res);
});

router.get("/doc-types/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get document type by ID'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getDocumentTypeById(req, res);
});

router.post("/doc-types", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Create document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.createDocumentType(req, res);
});

router.put("/doc-types/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Update document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.updateDocumentType(req, res);
});

router.delete("/doc-types/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Soft delete document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.deleteDocumentType(req, res);
});

// ==================== TERM ROWS ====================

router.get("/term-rows/:doc_type", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get term rows by document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getTermRowsByDocType(req, res);
});

router.post("/term-rows", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Create term row'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.createTermRow(req, res);
});

router.put("/term-rows/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Update term row'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.updateTermRow(req, res);
});

router.delete("/term-rows/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Delete term row'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.deleteTermRow(req, res);
});

// Add to your router file
router.get("/terms/:doc_type", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Get terms by document type'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.getTermsByDocType(req, res);
});

router.put("/term-rows/bulk", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Purchase Terms Postgre']
    #swagger.summary = 'Bulk update term rows (for reordering)'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  termsController.bulkUpdateTermRows(req, res);
});

module.exports = router;