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

router.use(authenticateToken);

// Departments – read: all onboarding roles, write: admin only
router.get('/departments',                  canViewOnboarding, asyncHandler(ctrl.getDepartments));
router.post('/departments',                 requireAdmin,      asyncHandler(ctrl.createDepartment));
router.put('/departments/reorder',          requireAdmin,      asyncHandler(ctrl.reorderDepartments));
router.put('/departments/:id',              requireAdmin,      asyncHandler(ctrl.updateDepartment));
router.delete('/departments/:id',           requireAdmin,      asyncHandler(ctrl.deleteDepartment));

// Processes – read: all onboarding roles, write: all onboarding roles (dept groups manage own)
router.get('/processes',                    canViewOnboarding, asyncHandler(ctrl.getProcesses));
router.post('/processes',                   canViewOnboarding, asyncHandler(ctrl.createProcess));
router.put('/processes/reorder',            canViewOnboarding, asyncHandler(ctrl.reorderProcesses));
router.put('/processes/:id',               canViewOnboarding, asyncHandler(ctrl.updateProcess));
router.delete('/processes/:id',            canViewOnboarding, asyncHandler(ctrl.deleteProcess));

module.exports = router;
