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

/**
 * @swagger
 * tags:
 *   name: QC
 *   description: Quality Control Sample Management APIs
 */

/**
 * @swagger
 * /api/qc/create:
 *   post:
 *     summary: Create a new QC Sample
 *     tags: [QC]
 *     security:
 *       - bearerAuth: []
 */

router.post(
  "/create",
    authenticate,
    authorize(["admin", "superadmin", "qc", "security"]),
  (req, res) => {
    /*
      #swagger.tags = ['QC']
      #swagger.summary = 'Create new QC Sample'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    qcController.createSample(req, res);
  },
);

router.get(
  "/all",
  authenticate,
  authorize(["admin", "superadmin", "qc", "security"]),
  (req, res) => {
    /*
      #swagger.tags = ['QC']
      #swagger.summary = 'Get QC Samples list with pagination & search'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    qcController.getAllSamples(req, res);
  },
);

router.get("/view/:id",authenticate,
    authorize(["admin", "superadmin", "qc", "security"]), (req, res) => {
  /*
      #swagger.tags = ['QC']
      #swagger.summary = 'Get QC Sample by ID'
      #swagger.parameters['id'] = {
          in: 'path',
          description: 'QC Sample ID',
          required: true,
          type: 'string'
      }
      #swagger.security = [{ "bearerAuth": [] }]
    */
  qcController.getSampleById(req, res);
});

// router.put(
//   "/update/:id",
// //   authenticate,
// //   authorize(["admin", "superadmin", "qa_manager", "lab_technician"]),
//   (req, res) => {
//     /*
//       #swagger.tags = ['QC']
//       #swagger.summary = 'Update QC Sample'
//       #swagger.security = [{ "bearerAuth": [] }]
//     */
//     qcController.updateSample(req, res);
//   },
// );
router.put("/update/:id",authenticate,
    authorize(["admin", "superadmin", "qc", "security"]), (req, res) => {
  /*
      #swagger.tags = ['QC']
      #swagger.summary = 'Update QC Sample'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        description: 'QC Sample ID',
        required: true,
        type: 'string'
      }

      #swagger.requestBody = {
        required: true,
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                poNumber: { type: "string", example: "PO123" },
                vehicleNumber: { type: "string", example: "TS09AB1234" },
                vendor: { type: "string", example: "ABC Vendor" },
                status: { type: "string", example: "APPROVED" },
                parameters: {
                  type: "array",
                  items: {
                    type: "object",
                    properties: {
                      parameterName: { type: "string", example: "Moisture" },
                      value: { type: "number", example: 12 }
                    }
                  }
                }
              }
            }
          }
        }
      }
    */
  qcController.updateSample(req, res);
});

router.delete("/delete/:id",authenticate,
    authorize(["admin", "superadmin", "qc", "security"]), (req, res) => {
  /*
      #swagger.tags = ['QC']
      #swagger.summary = 'Delete QC Sample (Soft Delete)'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        description: 'QC Sample ID',
        required: true,
        type: 'string'
      }
    */
  qcController.deleteSample(req, res);
});

router.get("/history/:sampleId",authenticate,
    authorize(["admin", "superadmin", "qc", "security"]), (req, res) => {
  qcController.getParameterHistory(req, res);
});


router.get("/pending-vehicles",authenticate,authorize(["admin", "superadmin", "qc", "security"]), (req, res) => {
  
qcController.getPendingVehiclesForQC(req, res);
})


router.put("/complete/:id", authenticate, authorize(["admin", "qc", "security"]), (req, res)=>{
  qcController.completeQC(req, res);
})

module.exports = router;
