// routes/inventory/outwardRoutes.js
const express = require("express");
const router = express.Router();
const outwardController = require("../../controllers/inventory/outwardController");
const authenticate = require("../../middlewares/authenticate");

// CREATE - Create new outward record
router.post(
  "/create",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Create a new outward/dispatch record'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['body'] = {
        in: 'body',
        required: true,
        schema: {
          vehicleNo: "TS09AB1234",
          vehicleType: "Goods Carrier",
          driverName: "Ravi Kumar",
          driverPhone: "9876543210",
          itemName: "Steel Pipes",
          quantity: 200,
          quantityUnit: "kg",
          outWeight: 12500,
          outWeightUnit: "kg",
          poNumber: "PO-001",
          warehouseId: 1,
          destination: "Chennai",
          remarks: "Handle with care"
        }
      }
    */
    outwardController.createOutward(req, res);
  }
);

// GET ALL - Get all outward records with pagination
router.get(
  "/",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Get all outward records with pagination and filters'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['page'] = { in: 'query', type: 'integer' }
      #swagger.parameters['limit'] = { in: 'query', type: 'integer' }
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['status'] = { in: 'query', type: 'string' }
      #swagger.parameters['startDate'] = { in: 'query', type: 'string' }
      #swagger.parameters['endDate'] = { in: 'query', type: 'string' }
      #swagger.parameters['sortBy'] = { in: 'query', type: 'string' }
      #swagger.parameters['sortOrder'] = { in: 'query', type: 'string' }
    */
    outwardController.getAllOutward(req, res);
  }
);

// GET STATS - Get outward statistics/dashboard
router.get(
  "/stats",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Get outward statistics for dashboard'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.getOutwardStats(req, res);
  }
);

// GENERATE NUMBER - Generate outward number
router.get(
  "/generate-number",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Generate a new outward number'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.generateOutwardNumber(req, res);
  }
);

// GET BY ID - Get single outward record
router.get(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Get outward record by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.getOutwardById(req, res);
  }
);

// UPDATE - Update outward record
router.put(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Update outward record'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.updateOutward(req, res);
  }
);

// MARK DISPATCH - Mark vehicle as dispatched
router.patch(
  "/:id/dispatch",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Mark vehicle as dispatched'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.markDispatch(req, res);
  }
);

// DELETE - Soft delete outward record
router.delete(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Outward']
      #swagger.summary = 'Soft delete outward record'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    outwardController.deleteOutward(req, res);
  }
);

module.exports = router;