



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

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

router.get(
  "/all",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Get all sales orders'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    salesOrderController.getSalesOrders(req, res);
  }
);

router.get(
  "/organization-details",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Get organization details'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    salesOrderController.getOrganizationDetails(req, res);
  }
);


router.post(
  "/create",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Create sales order'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    salesOrderController.createSalesOrder(req, res);
  }
);

router.post(
  "/invoice/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Create invoice from sales order'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        example: 1
      }
    */

    salesOrderController.createInvoiceFromSO(req, res);
  }
);

router.put(
  "/approve/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Approve sales order'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        example: 1
      }
    */

    salesOrderController.approveSalesOrder(req, res);
  }
);

router.put(
  "/update/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Update sales order'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        example: 1
      }
    */

    salesOrderController.updateSalesOrder(req, res);
  }
);

router.delete(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Delete sales order'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        example: 1
      }
    */

    salesOrderController.deleteSalesOrder(req, res);
  }
);

router.get(
  "/by-number/:soNumber",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Get sales order by number'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['soNumber'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: 'SO-001'
      }
    */

    salesOrderController.getSalesOrderByNumber(req, res);
  }
);

router.get(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Sales Orders']
      #swagger.summary = 'Get sales order by ID'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        example: 1
      }
    */

    salesOrderController.getSalesOrderById(req, res);
  }
);


module.exports = router;