

const express = require("express");
const router = express.Router();
const controller = require("../../controllers/securityops/configurationController");
const authenticate = require("../../middlewares/authenticate");
const authorize = require("../../middlewares/authorize");

/**
 * @swagger
 * tags:
 *   name: Prefix Configuration
 *   description: ERP Prefix & Sequence Management APIs
 */


router.post(
  "/create",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Create new prefix configuration'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.requestBody = {
        required: true,
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                moduleName: { type: "string", example: "VISITOR" },
                prefixCode: { type: "string", example: "VIS" },
                sequenceStart: { type: "number", example: 1 },
                paddingLength: { type: "number", example: 4 },
                separator: { type: "string", example: "-" },
                description: { type: "string", example: "Visitor prefix configuration" }
              }
            }
          }
        }
      }
    */
    controller.createPrefix(req, res);
  }
);


router.get(
  "/list",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Get all prefix configurations'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    controller.getPrefixes(req, res);
  }
);


router.get(
  "/:id",
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Get prefix configuration by ID'
      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '665f3f0c8f9b123456789abc'
      }
    */
    controller.getPrefixById(req, res);
  }
);


router.put(
  "/update/:id",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Update prefix configuration'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '665f3f0c8f9b123456789abc'
      }
    */
    controller.updatePrefix(req, res);
  }
);


router.delete(
  "/delete/:id",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Delete prefix configuration'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '665f3f0c8f9b123456789abc'
      }
    */
    controller.deletePrefix(req, res);
  }
);


//  ERP Critical API
router.post(
  "/generate-sequence",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Prefix Configuration']
      #swagger.summary = 'Generate next sequence number based on prefix'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.requestBody = {
        required: true,
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                moduleName: { type: "string", example: "VISITOR" }
              }
            }
          }
        }
      }
    */
    controller.generateSequence(req, res);
  }
);

module.exports = router;