// routes/admin/variantRoutes.js
const express = require("express");
const router = express.Router();
const variantController = require("../../controllers/admin/variantController");
const authenticate = require("../../middlewares/authenticate");
const authorize = require("../../middlewares/authorize");

/**
 * @swagger
 * tags:
 *   name: Variants
 *   description: Variant management APIs
 */

// CREATE Variant (admin only)
router.post("/create", authenticate, authorize("admin"), (req, res) => {
  /*
    #swagger.tags = ['Variants']
    #swagger.summary = 'Create a new variant'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Variant details including values array and orgId',
      required: true,
      schema: { 
        variantName: "Color", 
        values: ["Black", "Blue", "Red"],
        orgId: "64f5a2d8c9e4b3a1f0a12345"
      }
    }
  */
  variantController.createVariant(req, res);
});

// GET all Variants (admin + manager)
router.get("/get/all", authenticate, authorize(["admin", "manager"]), (req, res) => {
  /*
    #swagger.tags = ['Variants']
    #swagger.summary = 'Get all variants'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  variantController.getVariants(req, res);
});

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

// UPDATE Variant (admin only)
router.put("/update/:id", authenticate, authorize("admin"), (req, res) => {
  /*
    #swagger.tags = ['Variants']
    #swagger.summary = 'Update a variant by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Variant ID', required: true }
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Update data (variantName, values array, status, orgId)',
      required: true,
      schema: { 
        variantName: "Size", 
        values: ["S", "M", "L"],
        orgId: "64f5a2d8c9e4b3a1f0a12345",
        status: true
      }
    }
  */
  variantController.updateVariant(req, res);
});

// DELETE Variant (admin only)
router.delete("/delete/:id", authenticate, authorize("admin"), (req, res) => {
  /*
    #swagger.tags = ['Variants']
    #swagger.summary = 'Delete a variant by ID (soft delete)'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Variant ID', required: true }
  */
  variantController.deleteVariant(req, res);
});

module.exports = router;
