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

const expenseReimbursementController = require("../../controllers/postgre/expenseReimbursementController");
const authenticate = require("../../middlewares/authenticate");
const upload = require("../../middlewares/upload");

// Configure multer for single receipt upload
const receiptUpload = upload.single("receipt_upload");

/**
 * @swagger
 * tags:
 *   name: Expense Reimbursement
 *   description: Expense reimbursement creation, listing, update and deletion APIs
 */

/* ===========================
   ✅ CREATE EXPENSE REIMBURSEMENT
=========================== */

router.post(
  "/create",
  authenticate,
  receiptUpload,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Create expense reimbursement'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.createExpenseReimbursement(req, res);
  }
);

/* ===========================
   ✅ UPDATE EXPENSE REIMBURSEMENT
=========================== */

router.put(
  "/:id",
  authenticate,
  receiptUpload,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Update expense reimbursement by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.updateExpenseReimbursement(req, res);
  }
);

/* ===========================
   ✅ GET ALL EXPENSE REIMBURSEMENTS
=========================== */

router.get(
  "/all",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Get all expense reimbursements with filters'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.getExpenseReimbursements(req, res);
  }
);

/* ===========================
   ✅ GET EXPENSE SUMMARY
=========================== */

router.get(
  "/summary",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Get expense summary by employee'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.getExpenseSummary(req, res);
  }
);

/* ===========================
   ✅ GET EXPENSE TYPES
=========================== */

router.get(
  "/types",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Get all expense types'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.getExpenseTypes(req, res);
  }
);

/* ===========================
   ✅ GET EXPENSE REIMBURSEMENT BY ID
=========================== */

router.get(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Get expense reimbursement by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.getExpenseReimbursementById(req, res);
  }
);

/* ===========================
   ✅ GET EXPENSES BY ORGANIZATION
=========================== */

router.get(
  "/org/:org_id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Get expense reimbursements by organization ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.getExpensesByOrgId(req, res);
  }
);

/* ===========================
   ✅ DELETE EXPENSE REIMBURSEMENT
=========================== */

router.delete(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Expense Reimbursement']
      #swagger.summary = 'Delete expense reimbursement (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    expenseReimbursementController.deleteExpenseReimbursement(req, res);
  }
);

module.exports = router;