const express = require('express');
const {
  getAllSLAs,
  getSLA,
  createSLA,
  updateSLA,
  deleteSLA,
  getSLATrackers,
  getSLATracker,
  createSLATracker,
  markResponseMet,
  markResolutionMet,
  pauseSLATracker,
  resumeSLATracker,
  getSLAStats
} = require('../controllers/slaController');
const { protect } = require('../middleware/auth');
const { checkModulePermission, checkSpecialPermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/stats', checkModulePermission('sla', 'read'), getSLAStats);
router.get('/', checkModulePermission('sla', 'read'), getAllSLAs);
router.get('/:id', checkModulePermission('sla', 'read'), getSLA);
router.post('/', checkModulePermission('sla', 'create'), createSLA);
router.patch('/:id', checkModulePermission('sla', 'edit'), updateSLA);
router.delete('/:id', checkModulePermission('sla', 'delete'), deleteSLA);
router.get('/trackers/all', checkModulePermission('sla', 'read'), getSLATrackers);
router.get('/trackers/:id', checkModulePermission('sla', 'read'), getSLATracker);
router.post('/trackers', checkModulePermission('sla', 'create'), createSLATracker);
router.post('/trackers/:id/response-met', checkModulePermission('sla', 'edit'), markResponseMet);
router.post('/trackers/:id/resolution-met', checkModulePermission('sla', 'edit'), markResolutionMet);
router.post('/trackers/:id/pause', checkModulePermission('sla', 'edit'), pauseSLATracker);
router.post('/trackers/:id/resume', checkModulePermission('sla', 'edit'), resumeSLATracker);

module.exports = router;