const express = require('express');
const router = express.Router();
const ctrl = require('../controllers/itTopic.controller');
const { authenticateToken } = require('../middleware/auth');
const { requireAdmin } = require('../middleware/roleCheck');
const { asyncHandler } = require('../middleware/errorHandler');

router.use(authenticateToken);

// Read: admin + support; Write: admin only
router.post('/planner/sync', requireAdmin, asyncHandler(ctrl.syncToPlanner));
router.get('/',       asyncHandler(ctrl.getAll));
router.get('/:id',    asyncHandler(ctrl.getOne));
router.post('/',      requireAdmin, asyncHandler(ctrl.create));
router.put('/:id',    requireAdmin, asyncHandler(ctrl.update));
router.delete('/:id', requireAdmin, asyncHandler(ctrl.remove));

module.exports = router;
