const express = require("express");
const router = express.Router();
const shiftController = require("../../controllers/admin/shiftController");
const authenticate = require("../../middlewares/authenticate");
const authorize = require("../../middlewares/authorize");

/**
 * @swagger
 * tags:
 *   name: Shifts
 *   description: Shift management APIs
 */

// CREATE shift (admin only)
router.post("/create", authenticate, authorize("admin"), (req, res) => {
    /* 
      #swagger.tags = ['Shifts']
      #swagger.summary = 'Create a new shift'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['body'] = {
        in: 'body',
        description: 'Shift details including orgId',
        required: true,
        schema: { 
          shiftName: "Morning",
          startTime: "09:00",
          endTime: "12:00",
          orgId: "64f5a2d8c9e4b3a1f0a12345"
        }
      }
    */
    shiftController.createShift(req, res);
});

// GET all shifts (admin + manager allowed)
router.get("/get/all", authenticate, authorize(["admin", "manager"]), (req, res) => {
    /* 
      #swagger.tags = ['Shifts']
      #swagger.summary = 'Get all shifts'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    shiftController.getShifts(req, res);
});

// GET shift by ID (all logged in users)
router.get("/get/:id", authenticate, (req, res) => {
    /* 
      #swagger.tags = ['Shifts']
      #swagger.summary = 'Get a shift by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Shift ID', required: true }
    */
    shiftController.getShiftById(req, res);
});

// UPDATE shift (admin only)
router.put("/update/:id", authenticate, authorize("admin"), (req, res) => {
    /* 
      #swagger.tags = ['Shifts']
      #swagger.summary = 'Update a shift by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Shift ID', required: true }
      #swagger.parameters['body'] = {
        in: 'body',
        description: 'Update data (shiftName, startTime, endTime, status)',
        required: true,
        schema: { 
          shiftName: "Evening",
          startTime: "13:00",
          endTime: "17:00",
          status: "active"
        }
      }
    */
    shiftController.updateShift(req, res);
});

// DELETE shift (admin only)
router.delete("/delete/:id", authenticate, authorize("admin"), (req, res) => {
    /* 
      #swagger.tags = ['Shifts']
      #swagger.summary = 'Delete a shift by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Shift ID', required: true }
    */
    shiftController.deleteShift(req, res);
});

module.exports = router;
