const express = require("express");
const router = express.Router();

const payslipController = require("../../controllers/hrandpayrollsController/payslipController");
const authenticate = require("../../middlewares/authenticate");

/**
 * @swagger
 * tags:
 *   name: Payslip
 *   description: Payslip generation, download and view APIs
 */

/* ===========================
   ✅ DOWNLOAD PAYSLIP PDF
=========================== */
router.get(
  "/download/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Payslip']
      #swagger.summary = 'Download payslip as PDF'
      #swagger.security = [{ "bearerAuth": [] }]
      
      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        description: 'Payroll record ID',
        example: 123
      }
    */
    payslipController.downloadPayslip(req, res);
  }
);

/* ===========================
   ✅ VIEW PAYSLIP DATA
=========================== */
router.get(
  "/view/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Payslip']
      #swagger.summary = 'Get payslip data for viewing'
      #swagger.security = [{ "bearerAuth": [] }]
      
      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'integer',
        description: 'Payroll record ID',
        example: 123
      }
    */
    payslipController.viewPayslip(req, res);
  }
);

module.exports = router;