import { Router } from 'express';
import { hsnSacCodeController } from '../controllers/hsnSacCode.controller';
import { authenticateToken } from '../middlewares/auth.middleware';
import { requireAdmin } from '../middlewares/authorization.middleware';

const router = Router();

// All HSN/SAC routes require authentication
router.use(authenticateToken);

/**
 * @route GET /api/v1/hsn-sac
 * @desc Get all HSN/SAC codes
 * @access Private
 */
router.get('/', (req, res) => hsnSacCodeController.getAllCodes(req, res));

/**
 * @route GET /api/v1/hsn-sac/:id
 * @desc Get code by ID
 * @access Private
 */
router.get('/:id', (req, res) => hsnSacCodeController.getCodeById(req, res));

// Admin only routes for modification
router.use(requireAdmin);

/**
 * @route POST /api/v1/hsn-sac
 * @desc Create new HSN/SAC code
 * @access Private/Admin
 */
router.post('/', (req, res) => hsnSacCodeController.createCode(req, res));

/**
 * @route PATCH /api/v1/hsn-sac/:id
 * @desc Update HSN/SAC code
 * @access Private/Admin
 */
router.patch('/:id', (req, res) => hsnSacCodeController.updateCode(req, res));

/**
 * @route DELETE /api/v1/hsn-sac/:id
 * @desc Delete HSN/SAC code
 * @access Private/Admin
 */
router.delete('/:id', (req, res) => hsnSacCodeController.deleteCode(req, res));

/**
 * @route PATCH /api/v1/hsn-sac/:id/toggle-active
 * @desc Toggle active status
 * @access Private/Admin
 */
router.patch('/:id/toggle-active', (req, res) => hsnSacCodeController.toggleActive(req, res));

export default router;
