const express = require('express');
const router = express.Router();
const pageController = require('../controllers/pageController');
const pageCategoryController = require('../controllers/pageCategoryController');
const menuController = require('../controllers/menuController');
const { protect, adminOnly } = require('../middleware/authMiddleware');

// Public routes - Pages
router.get('/pages', pageController.getAllPages);
router.get('/pages/:id', pageController.getPageById);
router.get('/pages/slug/:slug', pageController.getPageBySlug);

// Public routes - Categories
router.get('/page-categories', pageCategoryController.getAllCategories);
router.get('/page-categories/:id', pageCategoryController.getCategoryById);
router.get('/page-categories/slug/:slug', pageCategoryController.getCategoryBySlug);

// Public routes - Menu
router.get('/menu-items', menuController.getAllMenuItems);
router.get('/menu-items/:id', menuController.getMenuItemById);
router.get('/menu/:location', menuController.getMenuTree);

// Admin routes - Pages
router.post('/pages', protect, adminOnly, pageController.createPage);
router.put('/pages/:id', protect, adminOnly, pageController.updatePage);
router.delete('/pages/:id', protect, adminOnly, pageController.deletePage);

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

// Admin routes - Menu
router.post('/menu-items', protect, adminOnly, menuController.createMenuItem);
router.put('/menu-items/:id', protect, adminOnly, menuController.updateMenuItem);
router.delete('/menu-items/:id', protect, adminOnly, menuController.deleteMenuItem);

module.exports = router;
