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


/**
 * @swagger
 * tags:
 *   name: Sales Orders
 *   description: Sales Orders APIs
 */


router.get("/all", authenticate, (req, res) => {
  // #swagger.tags = ['Sales Orders']
  // #swagger.summary = 'Get all sales orders with pagination & search'
  // #swagger.parameters['page'] = { in: 'query', description: 'Page number', type: 'integer' }
  salesOrderController.getSalesOrders(req, res);
});


router.delete("/:id", authenticate, (req,res) =>{
   salesOrderController.deleteSalesOrder(req, res)
});

router.get("/organization-details",authenticate,(req,res)=>{
    salesOrderController.getOrganizationDetails(req,res);
  }
);

router.get("/:id",authenticate, (req,res) =>{
    salesOrderController.getSalesOrderById(req, res)
});

router.post("/create", authenticate, (req,res)=>{
    salesOrderController.createSalesOrder(req, res)
})

router.put("/update/:id", authenticate, (req,res) =>{
   salesOrderController.updateSalesOrder(req, res)    
})

router.post("/invoice/:id", authenticate, (req,res)=>{
    salesOrderController.createInvoiceFromSO(req,res);
})



router.get("/by-number/:soNumber",authenticate, (req,res)=>{
    salesOrderController.getSalesOrderByNumber(req,res);
})


router.put("/approve/:id",
  authenticate,
  (req,res)=>{
    salesOrderController.approveSalesOrder(req,res);
})


router.post("/:id/resend-mail",
  authenticate,
  (req,res)=>{
    salesOrderController.resendSalesOrderMail(req,res);
})


module.exports = router;
