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

const router = express.Router();

router.get('/', SettingsController.getAll);
router.get('/groups', authenticate, authorize('admin', 'manager'), SettingsController.getGroups);
router.get('/:key', SettingsController.getByKey);
router.put(
  '/:key',
  authenticate,
  authorize('admin'),
  [
    body('setting_value').notEmpty().withMessage('Setting value required'),
    validate,
  ],
  SettingsController.update
);
router.post(
  '/bulk',
  authenticate,
  authorize('admin'),
  SettingsController.bulkUpdate
);

module.exports = router;
