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

// // CREATE
// router.post(
//   "/create",
//   authenticate,
//   upload.fields([
//     { name: "panFile" },
//     { name: "licenseFile" },
//     { name: "aadhaarFile" },
//     { name: "incorporationFile" },
//     { name: "chequeFile" },
//   ]),
//   (req,res) =>{


//     customerController.createCustomer(req,res);
//   }
// );

// // GET ALL
// router.get("/", customerController.getCustomers);

// // DELETE
// router.delete("/:id", customerController.deleteCustomer);

// module.exports = router;




const express = require("express");
const router = express.Router();

const customerController = require("../../controllers/sales/salesCustomerController");
const upload = require("../../middlewares/upload");
const authenticate = require("../../middlewares/authenticate");
// const authorize = require("../../middlewares/authorize");

/**
 * @swagger
 * tags:
 *   name: Customer Master
 *   description: Customer creation, listing and deletion APIs
 */

router.post(
  "/create",
  authenticate,
  upload.fields([
    { name: "panFile", maxCount: 1 },
    { name: "licenseFile", maxCount: 1 },
    { name: "aadhaarFile", maxCount: 1 },
    { name: "incorporationFile", maxCount: 1 },
    { name: "chequeFile", maxCount: 1 },
  ]),
  (req, res) => {
    /*
      #swagger.tags = ['Customer Master']
      #swagger.summary = 'Create Customer'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.consumes = ['multipart/form-data']

      #swagger.parameters['gst'] = {
        in: 'formData',
        type: 'string',
        example: '27ABCDE1234F1Z5'
      }

      #swagger.parameters['firstName'] = {
        in: 'formData',
        type: 'string',
        required: true,
        example: 'Ramesh'
      }

      #swagger.parameters['lastName'] = {
        in: 'formData',
        type: 'string',
        example: 'Kumar'
      }

      #swagger.parameters['phone'] = {
        in: 'formData',
        type: 'string',
        required: true,
        example: '9876543210'
      }

      #swagger.parameters['email'] = {
        in: 'formData',
        type: 'string',
        required: true,
        example: 'test@gmail.com'
      }

      #swagger.parameters['panFile'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['licenseFile'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['aadhaarFile'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['incorporationFile'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['chequeFile'] = {
        in: 'formData',
        type: 'file'
      }
    */

    customerController.createCustomer(req, res);
  }
);

router.put(
  "/:id",
  authenticate,
  upload.fields([
    { name: "panFile", maxCount: 1 },
    { name: "licenseFile", maxCount: 1 },
    { name: "aadhaarFile", maxCount: 1 },
    { name: "incorporationFile", maxCount: 1 },
    { name: "chequeFile", maxCount: 1 },
  ]),
  (req, res) =>{
authenticate,
    // swagger comments
    customerController.updateCustomer(req, res);
  }
);


router.get(
  "/download-template/",
  authenticate,
  (req, res) => {
     console.log("is api hitting heresadyguhjkl")
    customerController.downloadCustomerTemplate(req, res);
  }
);



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

    customerController.getCustomers(req, res);
  }
);

router.get(
  "/:id",
   authenticate,
    (req, res) => {
    
    /**
 * @swagger
 * /customers/{id}:
 *   get:
 *     summary: Get customer by ID
 *     tags: [Customer Master]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         example: C-17123456789
 *     responses:
 *       200:
 *         description: Customer details
 *       404:
 *         description: Not found
 */

     customerController.getCustomerById(req, res);
  }
   
  );

router.delete(
  "/:id",
  authenticate,
  // authorize(["admin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Customer Master']
      #swagger.summary = 'Delete customer (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    customerController.deleteCustomer(req, res);
  }
);


router.post(
  "/bulk-upload",
  authenticate,
  upload.single('file'),
  (req, res) => {
    customerController.bulkUploadCustomers(req, res);
  }
);

router.post("/check-gst",authenticate, (req,res)=>{
  customerController.checkGstDuplicate(req,res);
});



module.exports = router;