const express = require('express');
const {
  getAllProposals,
  getProposal,
  createProposal,
  updateProposal,
  deleteProposal,
  submitProposal,
  reviewProposal,
  verifyProposal,
  customerResponse,
  markAsViewed,
  getProposalStats,
  cloneProposal
} = require('../controllers/proposalController');
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/stats', checkModulePermission('proposals', 'read'), getProposalStats);
router.get('/', checkModulePermission('proposals', 'read'), getAllProposals);
router.get('/:id', checkModulePermission('proposals', 'read'), getProposal);
router.post('/', checkModulePermission('proposals', 'create'), createProposal);
router.post('/:id/clone', checkModulePermission('proposals', 'create'), cloneProposal);
router.post('/:id/submit', checkModulePermission('workflow', 'create'), submitProposal);
router.post('/:id/review', checkModulePermission('workflow', 'review'), reviewProposal);
router.post('/:id/verify', checkModulePermission('workflow', 'approve'), verifyProposal);
router.post('/:id/customer-response', customerResponse);
router.patch('/:id/viewed', markAsViewed);
router.patch('/:id', checkModulePermission('proposals', 'edit'), updateProposal);
router.delete('/:id', checkModulePermission('proposals', 'delete'), deleteProposal);

module.exports = router;