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

const router = express.Router();

router.get('/', authenticate, authorize('admin', 'manager'), NotificationController.getAll);
router.get('/booking/:bookingId', authenticate, authorize('admin', 'manager', 'staff'), NotificationController.getByBooking);
router.get('/:id', authenticate, authorize('admin', 'manager'), NotificationController.getById);
router.post(
  '/',
  authenticate,
  authorize('admin', 'manager'),
  [
    body('booking_id').isInt().withMessage('Booking ID required'),
    body('notification_type').isIn(['email', 'whatsapp', 'sms']).withMessage('Valid type required'),
    body('recipient').notEmpty().withMessage('Recipient required'),
    validate,
  ],
  NotificationController.create
);
router.put('/:id/status', authenticate, authorize('admin', 'manager'), NotificationController.updateStatus);

module.exports = router;
