const express = require('express');
const { body } = require('express-validator');
const validate = require('../middleware/validate');
const { authenticate, authorize } = require('../middleware/auth');
const ReviewController = require('../controllers/ReviewController');

const router = express.Router();

router.get('/', ReviewController.getAll);
router.get('/featured', ReviewController.getFeatured);
router.get('/:id', ReviewController.getById);
router.post(
  '/',
  [
    body('booking_id').isInt().withMessage('Booking ID required'),
    body('customer_id').isInt().withMessage('Customer ID required'),
    body('rating').isInt({ min: 1, max: 5 }).withMessage('Rating must be between 1 and 5'),
    validate,
  ],
  ReviewController.create
);
router.put('/:id', authenticate, authorize('admin', 'manager'), ReviewController.update);
router.delete('/:id', authenticate, authorize('admin'), ReviewController.remove);

module.exports = router;
