const express = require('express');
const router = express.Router();
const ctrl = require('../controllers/monthlyComparisonController');
const { createRequirePage } = require('../../../shared/middleware/pagePermission');
const { getDb } = require('../dbPool');
const requirePage = createRequirePage(getDb);

const ADMIN_ROLES = ['support_team', 'admin', 'system'];
function requireSupportTeam(req, res, next) {
    const role = (req.user?.role || '').toLowerCase();
    if (!ADMIN_ROLES.includes(role)) {
        return res.status(403).json({ success: false, message: '지원팀 이상 권한이 필요합니다.' });
    }
    next();
}

// 본인 월간 비교
router.get('/my-records', ctrl.getMyRecords);

// 특정 작업자 비교 (내부에서 권한 체크)
router.get('/records', ctrl.getRecords);

// 확인/반려
router.post('/confirm', ctrl.confirm);

// 전체 현황 (support_team+)
router.get('/all-status', requireSupportTeam, ctrl.getAllStatus);

// 엑셀 다운로드 (support_team+)
router.get('/export', requireSupportTeam, ctrl.exportExcel);

module.exports = router;
