const express = require('express');
const {
  getAllUsers,
  createUser,
  updateUser,
  updateUserStatus,
  deleteUser,
  resetPassword
} = require('../controllers/userController');
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/', checkModulePermission('users', 'read'), getAllUsers);
router.post('/', checkModulePermission('users', 'create'), createUser);
router.put('/:id', checkModulePermission('users', 'edit'), updateUser);
router.patch('/:id/status', checkModulePermission('users', 'edit'), updateUserStatus);
router.patch('/:id/password', checkModulePermission('users', 'edit'), resetPassword);
router.delete('/:id', checkModulePermission('users', 'delete'), deleteUser);

module.exports = router;