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

// const dailyConsumptionController = require("../../controllers/production/dailyConsumptionController");
// const authenticate = require("../../middlewares/authenticate");

// /**
//  * @swagger
//  * tags:
//  *   name: Daily Consumption
//  *   description: Daily consumption management - categories, items, logs, assignments, alerts
//  */

// /* ============================================================
//    SECTION 1 — CONSUMPTION CATEGORIES
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/categories:
//  *   get:
//  *     summary: Get all consumption categories
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: search
//  *         schema: { type: string }
//  *         description: Search by name or UOM
//  *       - in: query
//  *         name: status
//  *         schema: { type: string, enum: [Active, Inactive] }
//  *         description: Filter by status
//  */
// router.get("/categories", authenticate, (req, res) => {
//   dailyConsumptionController.getCategories(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories/{id}:
//  *   get:
//  *     summary: Get category by ID
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.get("/categories/:id", authenticate, (req, res) => {
//   dailyConsumptionController.getCategoryById(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories:
//  *   post:
//  *     summary: Create new category
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     requestBody:
//  *       required: true
//  *       content:
//  *         application/json:
//  *           schema:
//  *             type: object
//  *             required: [name, uom, cost_per_unit]
//  *             properties:
//  *               name: { type: string }
//  *               uom: { type: string }
//  *               cost_per_unit: { type: number }
//  *               description: { type: string }
//  *               status: { type: string, enum: [Active, Inactive], default: Active }
//  */
// router.post("/categories", authenticate, (req, res) => {
//   dailyConsumptionController.createCategory(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories/{id}:
//  *   put:
//  *     summary: Update category
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.put("/categories/:id", authenticate, (req, res) => {
//   dailyConsumptionController.updateCategory(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories/{id}:
//  *   delete:
//  *     summary: Delete category (soft delete)
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.delete("/categories/:id", authenticate, (req, res) => {
//   dailyConsumptionController.deleteCategory(req, res);
// });


// /* ============================================================
//    SECTION 2 — CONSUMPTION ITEMS
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/categories/{categoryId}/items:
//  *   get:
//  *     summary: Get items by category
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: categoryId
//  *         required: true
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: search
//  *         schema: { type: string }
//  *       - in: query
//  *         name: status
//  *         schema: { type: string, enum: [Active, Inactive] }
//  */
// router.get("/categories/:id/items", authenticate, (req, res) => {
//   dailyConsumptionController.getItemsByCategory(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/items/{id}:
//  *   get:
//  *     summary: Get item by ID
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.get("/items/:id", authenticate, (req, res) => {
//   dailyConsumptionController.getItemById(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories/{categoryId}/items:
//  *   post:
//  *     summary: Create new item under category
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: categoryId
//  *         required: true
//  *         schema: { type: integer }
//  *     requestBody:
//  *       required: true
//  *       content:
//  *         application/json:
//  *           schema:
//  *             type: object
//  *             required: [name, uom, cost_per_unit]
//  *             properties:
//  *               name: { type: string }
//  *               uom: { type: string }
//  *               cost_per_unit: { type: number }
//  *               status: { type: string, enum: [Active, Inactive], default: Active }
//  */
// router.post("/categories/:id/items", authenticate, (req, res) => {
//   dailyConsumptionController.createItem(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/items/{id}:
//  *   put:
//  *     summary: Update item
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.put("/items/:id", authenticate, (req, res) => {
//   dailyConsumptionController.updateItem(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/items/{id}:
//  *   delete:
//  *     summary: Delete item (soft delete)
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.delete("/items/:id", authenticate, (req, res) => {
//   dailyConsumptionController.deleteItem(req, res);
// });


// /* ============================================================
//    SECTION 3 — DAILY CONSUMPTION LOG
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/log:
//  *   get:
//  *     summary: Get consumption log entries
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: shift_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: entry_date
//  *         schema: { type: string, format: date }
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: category_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: from_date
//  *         schema: { type: string, format: date }
//  *       - in: query
//  *         name: to_date
//  *         schema: { type: string, format: date }
//  *       - in: query
//  *         name: page
//  *         schema: { type: integer, default: 1 }
//  *       - in: query
//  *         name: limit
//  *         schema: { type: integer, default: 100 }
//  */
// router.get("/log", authenticate, (req, res) => {
//   dailyConsumptionController.getConsumptionLog(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/log:
//  *   post:
//  *     summary: Create consumption log entry
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     requestBody:
//  *       required: true
//  *       content:
//  *         application/json:
//  *           schema:
//  *             type: object
//  *             required: [category_id, item_id, entry_date, shift_id, uom, quantity]
//  *             properties:
//  *               category_id: { type: integer }
//  *               item_id: { type: integer }
//  *               entry_date: { type: string, format: date }
//  *               shift_id: { type: integer }
//  *               role_id: { type: integer }
//  *               employee_id: { type: string }
//  *               quantity: { type: number }
//  *               uom: { type: string }
//  *               cost_per_unit: { type: number }
//  *               remarks: { type: string }
//  */
// router.post("/log", authenticate, (req, res) => {
//   dailyConsumptionController.createLogEntry(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/log/{id}:
//  *   put:
//  *     summary: Update consumption log entry
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.put("/log/:id", authenticate, (req, res) => {
//   dailyConsumptionController.updateLogEntry(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/log/{id}:
//  *   delete:
//  *     summary: Delete consumption log entry (soft delete)
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.delete("/log/:id", authenticate, (req, res) => {
//   dailyConsumptionController.deleteLogEntry(req, res);
// });


// /* ============================================================
//    SECTION 4 — SUMMARY / DASHBOARD
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/summary/shift:
//  *   get:
//  *     summary: Get consumption summary by shift for a date
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: entry_date
//  *         required: true
//  *         schema: { type: string, format: date }
//  */
// router.get("/summary/shift", authenticate, (req, res) => {
//   dailyConsumptionController.getSummaryByShift(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/summary/item:
//  *   get:
//  *     summary: Get consumption summary by item across date range
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: from_date
//  *         required: true
//  *         schema: { type: string, format: date }
//  *       - in: query
//  *         name: to_date
//  *         required: true
//  *         schema: { type: string, format: date }
//  */
// router.get("/summary/item", authenticate, (req, res) => {
//   dailyConsumptionController.getSummaryByItem(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/entry-form/items:
//  *   get:
//  *     summary: Get items for entry form with already logged flag
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: category_id
//  *         required: true
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: shift_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: entry_date
//  *         schema: { type: string, format: date }
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  */
// router.get("/entry-form/items", authenticate, (req, res) => {
//   dailyConsumptionController.getItemsForEntryForm(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/current-shift/status:
//  *   get:
//  *     summary: Get current shift status for logged-in role
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: current_time
//  *         schema: { type: string, pattern: 'HH:MM' }
//  */
// router.get("/current-shift/status", authenticate, (req, res) => {
//   dailyConsumptionController.getCurrentShiftStatus(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/missed-shift-entries:
//  *   get:
//  *     summary: Get completed shifts with missing entries
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: current_time
//  *         schema: { type: string, pattern: 'HH:MM' }
//  */
// router.get("/missed-shift-entries", authenticate, (req, res) => {
//   dailyConsumptionController.getMissedShiftEntries(req, res);
// });


// /* ============================================================
//    SECTION 5 — SHIFT ENTRY ASSIGNMENTS
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/assignments:
//  *   get:
//  *     summary: Get shift entry assignments
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: shift_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  */
// router.get("/assignments", authenticate, (req, res) => {
//   dailyConsumptionController.getAssignments(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/assignments:
//  *   post:
//  *     summary: Create shift entry assignment
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     requestBody:
//  *       required: true
//  *       content:
//  *         application/json:
//  *           schema:
//  *             type: object
//  *             required: [shift_id, role_id, category_id]
//  *             properties:
//  *               shift_id: { type: integer }
//  *               role_id: { type: integer }
//  *               category_id: { type: integer }
//  *               item_id: { type: integer }
//  *               is_mandatory: { type: boolean, default: true }
//  */
// router.post("/assignments", authenticate, (req, res) => {
//   dailyConsumptionController.createAssignment(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/assignments/{id}:
//  *   delete:
//  *     summary: Delete assignment (soft delete)
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.delete("/assignments/:id", authenticate, (req, res) => {
//   dailyConsumptionController.deleteAssignment(req, res);
// });


// /* ============================================================
//    SECTION 6 — ALERTS
// ============================================================ */

// /**
//  * @swagger
//  * /daily-consumption/alerts:
//  *   get:
//  *     summary: Get alerts for logged-in role
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: query
//  *         name: role_id
//  *         schema: { type: integer }
//  *       - in: query
//  *         name: admin
//  *         schema: { type: boolean }
//  *         description: Set to true for supervisor/admin view
//  */
// router.get("/alerts", authenticate, (req, res) => {
//   dailyConsumptionController.getAlerts(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/alerts/generate:
//  *   post:
//  *     summary: Generate alerts after shift ends
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     requestBody:
//  *       required: true
//  *       content:
//  *         application/json:
//  *           schema:
//  *             type: object
//  *             required: [shift_id]
//  *             properties:
//  *               shift_id: { type: integer }
//  *               entry_date: { type: string, format: date }
//  */
// router.post("/alerts/generate", authenticate, (req, res) => {
//   dailyConsumptionController.generateAlerts(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/alerts/{id}/resolve:
//  *   put:
//  *     summary: Resolve an alert
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: id
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.put("/alerts/:id/resolve", authenticate, (req, res) => {
//   dailyConsumptionController.resolveAlert(req, res);
// });

// /**
//  * @swagger
//  * /daily-consumption/categories/{categoryId}/items/{itemId}:
//  *   put:
//  *     summary: Update item
//  *     tags: [Daily Consumption]
//  *     security: [{ bearerAuth: [] }]
//  *     parameters:
//  *       - in: path
//  *         name: categoryId
//  *         required: true
//  *         schema: { type: integer }
//  *       - in: path
//  *         name: itemId
//  *         required: true
//  *         schema: { type: integer }
//  */
// router.put("/categories/:categoryId/items/:itemId", authenticate, (req, res) => {
//   dailyConsumptionController.updateItem(req, res);
// });

// module.exports = router;

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

const dailyConsumptionController = require("../../controllers/production/dailyConsumptionController");
const authenticate = require("../../middlewares/authenticate");

/**
 * @swagger
 * tags:
 *   name: Daily Consumption
 *   description: Daily consumption management - categories, items, logs, assignments, alerts
 */

/* ============================================================
   SECTION 1 — CONSUMPTION CATEGORIES
============================================================ */

/**
 * @swagger
 * /daily-consumption/categories:
 *   get:
 *     summary: Get all consumption categories
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: search
 *         schema: { type: string }
 *         description: Search by name or UOM
 *       - in: query
 *         name: status
 *         schema: { type: string, enum: [Active, Inactive] }
 *         description: Filter by status
 */
router.get("/categories", authenticate, (req, res) => {
  dailyConsumptionController.getCategories(req, res);
});

/**
 * @swagger
 * /daily-consumption/categories/{id}:
 *   get:
 *     summary: Get category by ID
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.get("/categories/:id", authenticate, (req, res) => {
  dailyConsumptionController.getCategoryById(req, res);
});

/**
 * @swagger
 * /daily-consumption/categories:
 *   post:
 *     summary: Create new category
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required: [name]
 *             properties:
 *               name: { type: string }
 *               description: { type: string }
 *               status: { type: string, enum: [Active, Inactive], default: Active }
 */
router.post("/categories", authenticate, (req, res) => {
  dailyConsumptionController.createCategory(req, res);
});

/**
 * @swagger
 * /daily-consumption/categories/{id}:
 *   put:
 *     summary: Update category
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.put("/categories/:id", authenticate, (req, res) => {
  dailyConsumptionController.updateCategory(req, res);
});

/**
 * @swagger
 * /daily-consumption/categories/{id}:
 *   delete:
 *     summary: Delete category (soft delete)
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.delete("/categories/:id", authenticate, (req, res) => {
  dailyConsumptionController.deleteCategory(req, res);
});


/* ============================================================
   SECTION 2 — CONSUMPTION ITEMS
============================================================ */

/**
 * @swagger
 * /daily-consumption/categories/{categoryId}/items:
 *   get:
 *     summary: Get items by category
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: categoryId
 *         required: true
 *         schema: { type: integer }
 *       - in: query
 *         name: search
 *         schema: { type: string }
 *       - in: query
 *         name: status
 *         schema: { type: string, enum: [Active, Inactive] }
 */
router.get("/categories/:id/items", authenticate, (req, res) => {
  dailyConsumptionController.getItemsByCategory(req, res);
});

/**
 * @swagger
 * /daily-consumption/items/{id}:
 *   get:
 *     summary: Get item by ID
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.get("/items/:id", authenticate, (req, res) => {
  dailyConsumptionController.getItemById(req, res);
});

/**
 * @swagger
 * /daily-consumption/categories/{categoryId}/items:
 *   post:
 *     summary: Create new item under category
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: categoryId
 *         required: true
 *         schema: { type: integer }
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required: [name]
 *             properties:
 *               name: { type: string }
 *               uom: { type: string }
 *               status: { type: string, enum: [Active, Inactive], default: Active }
 *               quantity: { type: number, default: 0 }
 */
router.post("/categories/:id/items", authenticate, (req, res) => {
  dailyConsumptionController.createItem(req, res);
});

/**
 * @swagger
 * /daily-consumption/items/{id}:
 *   put:
 *     summary: Update item
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.put("/items/:id", authenticate, (req, res) => {
  dailyConsumptionController.updateItem(req, res);
});

/**
 * @swagger
 * /daily-consumption/items/{id}:
 *   delete:
 *     summary: Delete item (soft delete)
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.delete("/items/:id", authenticate, (req, res) => {
  dailyConsumptionController.deleteItem(req, res);
});


/* ============================================================
   SECTION 3 — DAILY CONSUMPTION LOG
============================================================ */

/**
 * @swagger
 * /daily-consumption/log:
 *   get:
 *     summary: Get consumption log entries
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: shift_id
 *         schema: { type: integer }
 *       - in: query
 *         name: entry_date
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 *       - in: query
 *         name: category_id
 *         schema: { type: integer }
 *       - in: query
 *         name: from_date
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: to_date
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: page
 *         schema: { type: integer, default: 1 }
 *       - in: query
 *         name: limit
 *         schema: { type: integer, default: 100 }
 */
router.get("/log", authenticate, (req, res) => {
  dailyConsumptionController.getConsumptionLog(req, res);
});

/**
 * @swagger
 * /daily-consumption/log:
 *   post:
 *     summary: Create consumption log entry
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required: [category_id, item_id, entry_date, shift_id, quantity]
 *             properties:
 *               category_id: { type: integer }
 *               item_id: { type: integer }
 *               entry_date: { type: string, format: date }
 *               shift_id: { type: integer }
 *               role_id: { type: integer }
 *               employee_id: { type: string }
 *               quantity: { type: number }
 *               uom: { type: string }
 *               remarks: { type: string }
 *               status: { type: string, enum: [pending, updated, Completed, Active], default: pending }
 */
router.post("/log", authenticate, (req, res) => {
  dailyConsumptionController.createLogEntry(req, res);
});

/**
 * @swagger
 * /daily-consumption/log/{id}:
 *   put:
 *     summary: Update consumption log entry
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *     requestBody:
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               quantity: { type: number }
 *               uom: { type: string }
 *               remarks: { type: string }
 *               status: { type: string, enum: [pending, updated, Completed, Active] }
 */
router.put("/log/:id", authenticate, (req, res) => {
  dailyConsumptionController.updateLogEntry(req, res);
});

/**
 * @swagger
 * /daily-consumption/log/{id}:
 *   delete:
 *     summary: Delete consumption log entry (soft delete)
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.delete("/log/:id", authenticate, (req, res) => {
  dailyConsumptionController.deleteLogEntry(req, res);
});


/* ============================================================
   SECTION 4 — STATUS SUMMARY (CRITICAL FOR FRONTEND DASHBOARD)
============================================================ */

/**
 * @swagger
 * /daily-consumption/status-summary/overall:
 *   get:
 *     summary: Get overall consumption status counts
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     description: Returns total, completed, and pending consumption counts across all categories
 *     responses:
 *       200:
 *         description: Success
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success: { type: boolean }
 *                 data:
 *                   type: object
 *                   properties:
 *                     completed_count: { type: integer }
 *                     pending_count: { type: integer }
 *                     total_count: { type: integer }
 */
router.get("/status-summary/overall", authenticate, (req, res) => {
  dailyConsumptionController.getOverallStatusSummary(req, res);
});

/**
 * @swagger
 * /daily-consumption/status-summary/categories:
 *   get:
 *     summary: Get category-wise consumption status counts
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     description: Returns completed and pending counts per category for dashboard cards
 *     responses:
 *       200:
 *         description: Success
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success: { type: boolean }
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       category_id: { type: integer }
 *                       category_name: { type: string }
 *                       completed_count: { type: integer }
 *                       pending_count: { type: integer }
 *                       total_count: { type: integer }
 */
router.get("/status-summary/categories", authenticate, (req, res) => {
  dailyConsumptionController.getCategoryStatusSummary(req, res);
});

/**
 * @swagger
 * /daily-consumption/status-summary/shifts:
 *   get:
 *     summary: Get shift-wise consumption status counts
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: entry_date
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: shift_id
 *         schema: { type: integer }
 */
router.get("/status-summary/shifts", authenticate, (req, res) => {
  dailyConsumptionController.getShiftStatusSummary(req, res);
});


/* ============================================================
   SECTION 5 — SUMMARY / DASHBOARD
============================================================ */

/**
 * @swagger
 * /daily-consumption/summary/shift:
 *   get:
 *     summary: Get consumption summary by shift for a date
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: entry_date
 *         required: true
 *         schema: { type: string, format: date }
 */
router.get("/summary/shift", authenticate, (req, res) => {
  dailyConsumptionController.getSummaryByShift(req, res);
});

/**
 * @swagger
 * /daily-consumption/summary/item:
 *   get:
 *     summary: Get consumption summary by item across date range
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: from_date
 *         required: true
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: to_date
 *         required: true
 *         schema: { type: string, format: date }
 */
router.get("/summary/item", authenticate, (req, res) => {
  dailyConsumptionController.getSummaryByItem(req, res);
});

/**
 * @swagger
 * /daily-consumption/entry-form/items:
 *   get:
 *     summary: Get items for entry form with already logged flag
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: category_id
 *         required: true
 *         schema: { type: integer }
 *       - in: query
 *         name: shift_id
 *         schema: { type: integer }
 *       - in: query
 *         name: entry_date
 *         schema: { type: string, format: date }
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 */
router.get("/entry-form/items", authenticate, (req, res) => {
  dailyConsumptionController.getItemsForEntryForm(req, res);
});

/**
 * @swagger
 * /daily-consumption/current-shift/status:
 *   get:
 *     summary: Get current shift status for logged-in role
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 *       - in: query
 *         name: current_time
 *         schema: { type: string, pattern: 'HH:MM' }
 */
router.get("/current-shift/status", authenticate, (req, res) => {
  dailyConsumptionController.getCurrentShiftStatus(req, res);
});

/**
 * @swagger
 * /daily-consumption/missed-shift-entries:
 *   get:
 *     summary: Get completed shifts with missing entries
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 *       - in: query
 *         name: current_time
 *         schema: { type: string, pattern: 'HH:MM' }
 */
router.get("/missed-shift-entries", authenticate, (req, res) => {
  dailyConsumptionController.getMissedShiftEntries(req, res);
});


/* ============================================================
   SECTION 6 — SHIFT ENTRY ASSIGNMENTS
============================================================ */

/**
 * @swagger
 * /daily-consumption/assignments:
 *   get:
 *     summary: Get shift entry assignments
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: shift_id
 *         schema: { type: integer }
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 */
router.get("/assignments", authenticate, (req, res) => {
  dailyConsumptionController.getAssignments(req, res);
});

/**
 * @swagger
 * /daily-consumption/assignments:
 *   post:
 *     summary: Create shift entry assignment
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required: [shift_id, role_id, category_id]
 *             properties:
 *               shift_id: { type: integer }
 *               role_id: { type: integer }
 *               category_id: { type: integer }
 *               item_id: { type: integer }
 *               is_mandatory: { type: boolean, default: true }
 */
router.post("/assignments", authenticate, (req, res) => {
  dailyConsumptionController.createAssignment(req, res);
});

/**
 * @swagger
 * /daily-consumption/assignments/{id}:
 *   delete:
 *     summary: Delete assignment (soft delete)
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.delete("/assignments/:id", authenticate, (req, res) => {
  dailyConsumptionController.deleteAssignment(req, res);
});


/* ============================================================
   SECTION 7 — ALERTS
============================================================ */

/**
 * @swagger
 * /daily-consumption/alerts:
 *   get:
 *     summary: Get alerts for logged-in role
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: role_id
 *         schema: { type: integer }
 *       - in: query
 *         name: admin
 *         schema: { type: boolean }
 *         description: Set to true for supervisor/admin view
 */
router.get("/alerts", authenticate, (req, res) => {
  dailyConsumptionController.getAlerts(req, res);
});

/**
 * @swagger
 * /daily-consumption/alerts/generate:
 *   post:
 *     summary: Generate alerts after shift ends
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required: [shift_id]
 *             properties:
 *               shift_id: { type: integer }
 *               entry_date: { type: string, format: date }
 */
router.post("/alerts/generate", authenticate, (req, res) => {
  dailyConsumptionController.generateAlerts(req, res);
});

/**
 * @swagger
 * /daily-consumption/alerts/{id}/resolve:
 *   put:
 *     summary: Resolve an alert
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 */
router.put("/alerts/:id/resolve", authenticate, (req, res) => {
  dailyConsumptionController.resolveAlert(req, res);
});

// POST endpoint to receive stock from PR
router.post('/stock/receive-from-pr', 
  authenticate, 
  dailyConsumptionController.receiveStockFromPR
);
/* ============================================================
   SECTION 8 — ADDITIONAL ROUTES
============================================================ */

/**
 * @swagger
 * /daily-consumption/categories/{categoryId}/items/{itemId}:
 *   put:
 *     summary: Update item by category and item ID
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: path
 *         name: categoryId
 *         required: true
 *         schema: { type: integer }
 *       - in: path
 *         name: itemId
 *         required: true
 *         schema: { type: integer }
 */
router.put("/categories/:categoryId/items/:itemId", authenticate, (req, res) => {
  dailyConsumptionController.updateItem(req, res);
});

/**
 * @swagger
 * /daily-consumption/stock/available:
 *   get:
 *     summary: Get available stock for multiple items by item_code
 *     tags: [Daily Consumption]
 *     security: [{ bearerAuth: [] }]
 *     parameters:
 *       - in: query
 *         name: item_codes
 *         required: true
 *         schema: { type: string }
 *         description: Comma-separated list of item codes e.g. ITM001,ITM002
 */
router.get("/stock/available", authenticate, (req, res) => {
  dailyConsumptionController.getAvailableStockByItemCodes(req, res);
});

module.exports = router;