// routes/departmentRoutes.js
const express = require('express');
const router = express.Router();
const departmentController = require('../controllers/departmentController');
const { requireAuth } = require('../middlewares/auth');
const { createRequirePage } = require('../../../shared/middleware/pagePermission');
const { getDb } = require('../dbPool');
const requirePage = createRequirePage(getDb);

// 부서 목록 조회 (인증 필요)
router.get('/', requireAuth, departmentController.getAll);

// 부서 상세 조회
router.get('/:id', requireAuth, departmentController.getById);

// 부서별 작업자 조회
router.get('/:id/workers', requireAuth, departmentController.getWorkers);

// 부서 생성 (관리자만)
router.post('/', requireAuth, requirePage('factory_departments'), departmentController.create);

// 부서 수정 (관리자만)
router.put('/:id', requireAuth, requirePage('factory_departments'), departmentController.update);

// 부서 삭제 (관리자만)
router.delete('/:id', requireAuth, requirePage('factory_departments'), departmentController.delete);

// 작업자 부서 이동 (관리자만)
router.post('/move-worker', requireAuth, requirePage('factory_departments'), departmentController.moveWorker);

// 여러 작업자 부서 일괄 이동 (관리자만)
router.post('/move-workers', requireAuth, requirePage('factory_departments'), departmentController.moveWorkers);

module.exports = router;
