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

const router = express.Router();

router.get('/', VehicleController.getAll);
router.get('/types', VehicleController.getTypes);
router.get('/:id', VehicleController.getById);
router.post(
  '/',
  authenticate,
  authorize('admin', 'manager'),
  [
    body('vehicle_code').notEmpty().withMessage('Vehicle code required'),
    body('vehicle_type').isIn(['economy', 'vip', 'premium', 'standard']).withMessage('Valid vehicle type required'),
    body('vehicle_name').notEmpty().withMessage('Vehicle name required'),
    body('capacity').isInt({ min: 1 }).withMessage('Capacity must be at least 1'),
    validate,
  ],
  VehicleController.create
);
router.put('/:id', authenticate, authorize('admin', 'manager'), VehicleController.update);
router.delete('/:id', authenticate, authorize('admin'), VehicleController.remove);

module.exports = router;
