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

const router = express.Router();

router.get('/', authenticate, authorize('admin', 'manager'), DriverController.getAll);
router.get('/:id', authenticate, authorize('admin', 'manager', 'staff'), DriverController.getById);
router.post(
  '/',
  authenticate,
  authorize('admin', 'manager'),
  [
    body('driver_code').notEmpty().withMessage('Driver code required'),
    body('full_name').notEmpty().withMessage('Full name required'),
    body('phone').notEmpty().withMessage('Phone required'),
    body('license_number').notEmpty().withMessage('License number required'),
    validate,
  ],
  DriverController.create
);
router.put('/:id', authenticate, authorize('admin', 'manager'), DriverController.update);
router.delete('/:id', authenticate, authorize('admin'), DriverController.remove);

module.exports = router;
