const express = require('express');
const router = express.Router();
const { body } = require('express-validator');
const usersController = require('../controllers/users.controller');
const { authenticate, authorize } = require('../middleware/auth.middleware');
const { ROLES } = require('../utils/roles');

router.use(authenticate);
router.get('/', usersController.getAll);
router.get('/:id', usersController.getById);
router.post('/', authorize(ROLES.SUPER_ADMIN, ROLES.DIRECTOR), [
  body('email').isEmail().normalizeEmail(),
  body('password').isLength({ min: 8 }),
  body('firstName').trim().notEmpty(),
  body('lastName').trim().notEmpty(),
  body('role').isIn(Object.values(ROLES)),
], usersController.create);
router.patch('/:id', authorize(ROLES.SUPER_ADMIN, ROLES.DIRECTOR), usersController.update);
module.exports = router;
