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

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



router.post(
  "/create",
    authenticate,
    // authorize(["admin", "superadmin", "qc", "security"]),
  (req, res) => {
    /*
      #swagger.tags = ['QC Check Postgre' ]
      #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 Check Postgre']
      #swagger.summary = 'Get QC Samples list with pagination & search'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    qcController.getAllSamples(req, res);
  },
);



router.put("/update/:id",authenticate,
    // authorize(["admin", "superadmin", "qc", "security"]), 
    (req, res) => {
  /*
      #swagger.tags = ['QC Check Postgre']
      #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);
});


// GET QC history by sampleId
router.get(
  "/history/:sampleId",
  authenticate,
  (req, res) => {
    qcController.getParameterHistory(req, res);
  }
  /*
    #swagger.tags = ['QC Check Postgre']
    #swagger.summary = 'Get QC parameter history by sample ID'
    #swagger.security = [{ "bearerAuth": [] }]
  */
);

router.put(
  "/complete/:id",
  authenticate,
  // authorize(["admin", "qc", "security"]),
  (req, res) => {
    qcController.completeQC(req, res);
  }
  /*
    #swagger.tags = ['QC Check Postgre']
    #swagger.summary = 'Complete QC process'
    #swagger.security = [{ "bearerAuth": [] }]
  */
);


router.post("/dispatch-qc/create", authenticate, (req, res) => {
    qcController.createDispatchQC(req,res);
  }
);


router.get("/:id/download",authenticate, (req, res) => {
    qcController.downloadQCCertificate(req,res);
  }
);
module.exports = router;