/**
 * Vacation Routes
 *
 * 휴가 유형 + 연차 배정 라우팅
 * Sprint 001: worker → user 전환 + 장기근속
 */

const express = require('express');
const router = express.Router();
const vc = require('../controllers/vacationController');
const { requireAuth, requireAdminOrPermission } = require('../middleware/auth');
const { createRequirePage } = require('../../../shared/middleware/pagePermission');
const { getPool } = require('../../shared/config/database');
const requirePage = createRequirePage(getPool);

const vacPerm = requireAdminOrPermission('tkuser.vacations');

// Vacation Types (휴가 유형)
router.get('/types', requireAuth, vc.getVacationTypes);
router.post('/types', vacPerm, vc.createVacationType);
router.put('/types/priorities', vacPerm, vc.updatePriorities);
router.put('/types/:id', vacPerm, vc.updateVacationType);
router.delete('/types/:id', vacPerm, vc.deleteVacationType);

// Vacation Balances (연차 배정)
router.get('/balances/year/:year', vacPerm, vc.getBalancesByYear);
router.get('/balances/user/:userId/year/:year', requireAuth, vc.getBalancesByUserYear);
router.post('/balances', vacPerm, vc.createBalance);
router.post('/balances/bulk-upsert', vacPerm, vc.bulkUpsertBalances);
router.post('/balances/auto-calculate', vacPerm, vc.autoCalculate);
router.put('/balances/:id', vacPerm, vc.updateBalance);
router.delete('/balances/:id', vacPerm, vc.deleteBalance);

// 장기근속 제외 설정
router.put('/long-service-exclusion', requirePage('tkuser.vacations'), vc.setLongServiceExclusion);

module.exports = router;
