const express = require("express");
const router = express.Router();
const termsConditionsController = require("../../controllers/postgre/termsConditionsController");
const authenticate = require("../../middlewares/authenticate");

// ========================
// SECTIONS ROUTES
// ========================

// GET all sections
router.get(
  "/sections",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Get all sections'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.getAllSections(req, res);
  }
);

// POST create new section
router.post(
  "/sections",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Create a new section'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.addSection(req, res);
  }
);

// PUT update section
router.put(
  "/sections/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Update section by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.updateSection(req, res);
  }
);

// DELETE section
router.delete(
  "/sections/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Delete section by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.deleteSection(req, res);
  }
);

// ========================
// TEMPLATES ROUTES
// ========================

// GET all templates
router.get(
  "/templates",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Get all templates by module type'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['module_type'] = { in: 'query', type: 'string', description: 'purchase_order or quotation' }
    */
    termsConditionsController.getAllTemplates(req, res);
  }
);

// POST create new template
router.post(
  "/templates",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Create a new template'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.addTemplate(req, res);
  }
);

// PUT update template
router.put(
  "/templates/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Update template by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.updateTemplate(req, res);
  }
);

// DELETE template
router.delete(
  "/templates/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Delete template by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.deleteTemplate(req, res);
  }
);

// PUT set default template
router.put(
  "/templates/:id/default",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Terms & Conditions']
      #swagger.summary = 'Set template as default'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    termsConditionsController.setDefaultTemplate(req, res);
  }
);

module.exports = router;