const express = require('express');
const router = express.Router();
const { requireAuth, requirePage } = require('../middleware/auth');
const ctrl = require('../controllers/vacationController');

router.use(requireAuth);

// 참조 데이터
router.get('/types', ctrl.getVacationTypes);

// 휴가 신청
router.post('/requests', requirePage('support_vacation_request'), ctrl.createRequest);
router.get('/requests', ctrl.getRequests);
router.get('/requests/:id', ctrl.getRequestById);
router.put('/requests/:id', requirePage('support_vacation_request'), ctrl.updateRequest);
router.patch('/requests/:id/cancel', requirePage('support_vacation_request'), ctrl.cancelRequest);

// 승인
router.get('/pending', requirePage('support_vacation_approval'), ctrl.getPending);
router.patch('/requests/:id/approve', requirePage('support_vacation_approval'), ctrl.approveRequest);
router.patch('/requests/:id/reject', requirePage('support_vacation_approval'), ctrl.rejectRequest);

// 내 휴가 현황
router.get('/my-status', ctrl.getMyStatus);

// 잔여일
router.get('/balance', ctrl.getMyBalance);
router.get('/balance/all', requirePage('support_vacation_approval'), ctrl.getAllBalances);
router.get('/balance/:userId', requirePage('support_vacation_approval'), ctrl.getUserBalance);
router.post('/balance/allocate', requirePage('support_vacation_approval'), ctrl.allocateBalance);

// 관리자 보정
router.post('/admin/correct', requirePage('support_vacation_admin'), ctrl.adminCreateRequest);
router.delete('/admin/requests/:id', requirePage('support_vacation_admin'), ctrl.adminDeleteRequest);

// 사용자 목록
router.get('/users', requirePage('support_vacation_approval'), ctrl.getUsers);

module.exports = router;
