const express = require('express');
const router = express.Router();
const projectController = require('../controllers/project.controller');
const { verifyToken, checkRole, roles } = require('../middleware/auth.middleware');

// Get all projects (requires authentication)
router.get('/', verifyToken, projectController.getAllProjects);

// Get project by id
router.get('/:id', verifyToken, projectController.getProjectById);

// Create new project (only super_admin and admin)
router.post('/', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.createProject
);

// Update project (only super_admin and admin)
router.put('/:id', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.updateProject
);

// Delete project (only super_admin and admin)
router.delete('/:id', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.deleteProject
);

// Generate shared link for a project
router.post('/:id/share', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.generateShareLink
);

// Get share information for a project
router.get('/:id/share', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.getProjectShareInfo
);

// Access shared project (no auth required)
router.get('/shared/:shareId', projectController.getSharedProject);

// Verify share password
router.post('/shared/:shareId/verify', projectController.verifySharePassword);

// Get all shareable projects for an admin
router.get('/shareable/all', 
  verifyToken, 
  checkRole([roles.SUPER_ADMIN, roles.ADMIN]), 
  projectController.getAllShareableProjects
);

module.exports = router;
