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

/**
 * @swagger
 * /api/contracts:
 *   post: summary: Create new sales contract
 */
router.post("/create",authenticate, (req,res) =>{
    /*  
  #swagger.tags = ['Sales Contract']
  #swagger.summary = 'Create a new sales contract'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.parameters['body'] = {
    in: 'body',
    required: true,
    schema: {
      type: 'object',
      properties: {
        contract_no: { type: 'string', example: 'CNT-001' },
        customer_id: { type: 'integer', example: 12 },
        product_id: { type: 'integer', example: 3 },
        contract_qty: { type: 'number', example: 1000 },
        rate: { type: 'number', example: 92000 },
        valid_from: { type: 'string', format: 'date', example: '2026-04-01' },
        valid_to: { type: 'string', format: 'date', example: '2026-12-31' },
        delivery_terms: { type: 'string', example: 'Ex-Depot' },
        govt_allocation_ref: { type: 'string', example: 'GOI-ETH-2026-01' },
        remarks: { type: 'string', example: 'Monthly supply basis' }
      }
    }
  }
*/
  salesContractController.createContract(req,res) 
}
);


router.get("/", authenticate, (req, res) => {
  /*
  #swagger.tags = ['Sales Contract']
  #swagger.summary = 'Get all contracts (with pagination & filters)'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.parameters['page'] = { in: 'query', type: 'integer', example: 1 }
  #swagger.parameters['limit'] = { in: 'query', type: 'integer', example: 10 }
  #swagger.parameters['status'] = { in: 'query', type: 'string', example: 'ACTIVE' }
  #swagger.parameters['search'] = { in: 'query', type: 'string', example: 'CNT' }
  */
  salesContractController.getContracts(req, res);
});

router.get("/:id", authenticate, (req, res) => {
  /*
  #swagger.tags = ['Sales Contract']
  #swagger.summary = 'Get contract details by ID'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.parameters['id'] = { in: 'path', required: true, type: 'integer', example: 1 }
  */
  salesContractController.getContractById(req, res);
});

router.put("/:id", authenticate, (req, res) => {
  /*
  #swagger.tags = ['Sales Contract']
  #swagger.summary = 'Update contract details'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.parameters['id'] = { in: 'path', required: true, type: 'integer', example: 1 }
  #swagger.parameters['body'] = {
    in: 'body',
    schema: {
      type: 'object',
      properties: {
        contract_no: { type: 'string', example: 'CNT-002' },
        contract_qty: { type: 'number', example: 1500 },
        rate: { type: 'number', example: 95000 },
        valid_to: { type: 'string', example: '2026-12-31' },
        status: { type: 'string', example: 'ACTIVE' },
        remarks: { type: 'string', example: 'Updated contract' }
      }
    }
  }
  */
  salesContractController.updateContract(req, res);
});
router.delete("/:id", authenticate, (req,res)=>{
     /*
  #swagger.tags = ['Sales Contract']
  #swagger.summary = 'Delete contract by ID'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.parameters['id'] = { in: 'path', required: true, type: 'integer', example: 1 }
  */
    salesContractController.deleteContract(req,res);
});

router.get("/customer/:customer_code", authenticate, (req,res) =>{
       salesContractController.getContractsByCustomer(req,res);
})

module.exports = router;