const express = require("express");
const router = express.Router();
const documentController = require("../controllers/documentController");
const authenticate = require("../middlewares/authenticate");
const authorize = require("../middlewares/authorize");
const upload = require("../middlewares/upload");


/**
 * @swagger
 * tags:
 *   name: Documents
 *   description: Document management APIs
 */

router.post(
  "/create",
  authenticate,
  // authorize(["admin", "superadmin"]),
  authorize(["admin", "superadmin", "manager"]),
  upload.single("file"),
  (req, res) => {
    /*
      #swagger.tags = ['Documents']
      #swagger.summary = 'Create a new document'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    documentController.createDocument(req, res);
  }
);

router.get("/", authenticate, authorize(["admin", "manager"]), (req, res) => {
  // #swagger.tags = ['Documents']
  // #swagger.summary = 'Get all documents'
  // #swagger.security = [{ "bearerAuth": [] }]

  documentController.getAllDocuments(req, res);
});

router.get("/:id", authenticate, authorize(["admin", "manager"]), (req, res) => {
  // #swagger.tags = ['Documents']
  // #swagger.summary = 'Get document by ID'
  // #swagger.security = [{ "bearerAuth": [] }]

  documentController.getDocumentById(req, res);
});

// DELETE Document
router.delete("/delete/:id", authenticate, authorize(["admin", "manager"]), (req, res) => {
  /*
    #swagger.tags = ['Documents']
    #swagger.summary = 'Soft delete a document by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Document ID', required: true }
  */
  documentController.deleteDocument(req, res);
});

router.put("/update/:id", authenticate, authorize(["admin", "manager"]), upload.single("file"), (req, res) => {
  /*
    #swagger.tags = ['Documents']
    #swagger.summary = 'Update a document by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Document ID', required: true }
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Update fields for document',
      required: true,
      schema: { status: "In Progress", priority: "Medium", assignedTo: "Jane Doe" }
    }
  */
  // req.body.orgId = req.body.orgId || req.user?.orgId;
  documentController.updateDocument(req, res);
});

module.exports = router;
