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

/**
 * @swagger
 * tags:
 *   name: Branches
 *   description: Branch management APIs
 */

router.post(
  "/create",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Branches']
      #swagger.summary = 'Create a new branch'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    branchController.createBranch(req, res);
  }
);


router.get(
  "/",
  authenticate,
  authorize(["admin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Branches']
      #swagger.summary = 'Get all branches'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['page'] = { in: 'query', type: 'number' }
      #swagger.parameters['limit'] = { in: 'query', type: 'number' }
    */
    branchController.getBranches(req, res);
  }
);

router.get(
  "/:id",
  authenticate,
  authorize(["admin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Branches']
      #swagger.summary = 'Get a branch by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    branchController.getBranchById(req, res);
  }
);


// router.put(
//   "/:id",
//   authenticate,
//   authorize(["admin", "superadmin"]),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Branches']
//       #swagger.summary = 'Update branch details'
//       #swagger.security = [{ "bearerAuth": [] }]
//     */
//     branchController.updateBranch(req, res);
//   }
// );

router.put(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {

    /*
      #swagger.tags = ['Branches']
      #swagger.summary = 'Update branch details'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        description: 'Branch ID',
        required: true,
        type: 'string',
        example: '65f1c2e4a1b2c3d4e5f67890'
      }

      #swagger.parameters['body'] = {
        in: 'body',
        description: 'Branch update information',
        required: true,
        schema: {
          branchName: "Hyderabad Main Branch",
          branchCode: "HYD001",
          branchType: "Urban",
          manager: "65f1c2e4a1b2c3d4e5f67890",

          address: {
            street: "Plot No 12",
            area: "Madhapur",
            city: "Hyderabad",
            state: "Telangana",
            postalCode: "500081"
          },

          contact: {
            phone: "9876543210",
            email: "hydbranch@example.com"
          },

          status: "Active",
          notes: "Main branch updated"
        }
      }
    */

    branchController.updateBranch(req, res);
  }
);



router.delete(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Branches']
      #swagger.summary = 'Delete branch (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    branchController.deleteBranch(req, res);
  }
);

module.exports = router;
