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



router.post("/create",authenticate, (req,res) =>{
    salesInvoiceController.createInvoice(req,res);
});

router.get("/list",authenticate, (req,res)=>{
    salesInvoiceController.getInvoices(req,res)
});

router.get("/stats",authenticate, (req,res)=>{
    salesInvoiceController.getInvoiceStats(req,res);
});

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

router.delete("/:id", authenticate, (req, res)=>{
    salesInvoiceController.deleteInvoice(req,res)
})

router.put("/:id",authenticate, (req, res)=>{
    salesInvoiceController.updateInvoice(req,res)
})


router.get("/download/:id", authenticate, (req,res)=>{
    salesInvoiceController.downloadInvoicePDF(req,res);
});


router.post("/:id/super-approve", authenticate, (req,res) =>{
    salesInvoiceController.superApproveInvoice(req,res);
  }
);

router.get("/:id/approval-status",
  authenticate,
  (req,res)=>{
    salesInvoiceController.getInvoiceApprovalStatus(req,res);
  }
);


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



// Sales Invoice routes
router.post("/create-main", salesInvoiceController.createMainInvoice);
router.post("/create-proforma", salesInvoiceController.createProformaInvoice);

// Add this to your routes
router.put("/:id/weighment-status", salesInvoiceController.updateVehicleWeighmentStatus);
router.get("/:id/history", salesInvoiceController.getSalesOrderInvoiceHistory);


// Add to your routes file
router.put("/:id/cancel", salesInvoiceController.cancelInvoice);
router.put("/proformaInvoice/:id/cancel", salesInvoiceController.cancelProformaInvoice);

module.exports = router;