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

// 회의록
router.get('/', ctrl.getAll);
router.get('/action-items', ctrl.getActionItems);
router.get('/:id', ctrl.getById);
router.post('/', requirePage('factory_meetings'), ctrl.create);
router.put('/:id', requirePage('factory_meetings'), ctrl.update);
router.put('/:id/publish', requirePage('factory_meetings'), ctrl.publish);
router.put('/:id/unpublish', requirePage('factory_meetings'), ctrl.unpublish);
router.delete('/:id', requirePage('factory_meetings'), ctrl.delete);

// 안건
router.post('/:id/items', requirePage('factory_meetings'), ctrl.addItem);
router.put('/:id/items/:itemId', requirePage('factory_meetings'), ctrl.updateItem);
router.delete('/:id/items/:itemId', requirePage('factory_meetings'), ctrl.deleteItem);

// 조치상태 업데이트
router.put('/items/:itemId/status', requirePage('factory_meetings'), ctrl.updateItemStatus);

module.exports = router;
