const express = require('express');
const router = express.Router();
const {
  getAllCategories,
  getActiveCategories,
  getCategoryById,
  getCategoryBySlug,
  getCategoryWithSubCategories,
  createCategory,
  updateCategory,
  deleteCategory
} = require('../controllers/categoryController');
const { protect, adminOnly } = require('../middleware/authMiddleware');

// Public routes
router.get('/', getAllCategories);
router.get('/active', getActiveCategories);
router.get('/:id', getCategoryById);
router.get('/slug/:slug', getCategoryBySlug);
router.get('/:id/subcategories', getCategoryWithSubCategories);

// Admin routes
router.post('/', protect, adminOnly, createCategory);
router.put('/:id', protect, adminOnly, updateCategory);
router.delete('/:id', protect, adminOnly, deleteCategory);

module.exports = router;
