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

// READ - 인증된 사용자
router.get('/', requireAuth, projectController.getAllProjects);
router.get('/active/list', requireAuth, projectController.getActiveProjects);
router.get('/:project_id', requireAuth, projectController.getProjectById);

// CREATE/UPDATE - support_team 이상 권한 필요
router.post('/', requireAuth, requirePage('factory_projects'), projectController.createProject);
router.put('/:project_id', requireAuth, requirePage('factory_projects'), projectController.updateProject);

// DELETE - admin 이상 권한 필요
router.delete('/:project_id', requireAuth, requirePage('factory_projects'), projectController.removeProject);

module.exports = router;