/**
 * Permission Routes
 */

const express = require('express');
const router = express.Router();
const permissionController = require('../controllers/permissionController');
const { requireAuth, requireAdmin } = require('../middleware/auth');

// 권한 부여 (admin)
router.post('/grant', requireAdmin, permissionController.grantPermission);
router.post('/bulk-grant', requireAdmin, permissionController.bulkGrant);

// 접근 권한 확인 (auth)
router.get('/check/:uid/:page', requireAuth, permissionController.checkAccess);

// 설정 가능 페이지 목록 (auth)
router.get('/available-pages', requireAuth, permissionController.getAvailablePages);

// 부서별 권한 (admin)
router.get('/departments/:deptId/permissions', requireAdmin, permissionController.getDepartmentPermissions);
router.post('/departments/:deptId/bulk-set', requireAdmin, permissionController.bulkSetDepartmentPermissions);

// 출처 포함 사용자 권한 조회 (admin or self)
router.get('/users/:userId/effective-permissions', requireAuth, permissionController.getUserPermissionsWithSource);

// 권한 삭제 (admin)
router.delete('/:id', requireAdmin, permissionController.deletePermission);

module.exports = router;
