const express = require('express');
const {
  getAllCompanies,
  getCompany,
  createCompany,
  updateCompany,
  deleteCompany,
  updateCompanyStatus,
  getCompanyUsers,
  getCompanyStats,
  updateCompanySettings
} = require('../controllers/companyController');
const { protect, checkCompanyAccess } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/', checkModulePermission('companies', 'read'), getAllCompanies);
router.get('/:id', checkModulePermission('companies', 'read'), getCompany);
router.get('/:id/users', checkModulePermission('companies', 'read'), getCompanyUsers);
router.get('/:id/stats', checkModulePermission('companies', 'read'), getCompanyStats);
router.post('/', checkModulePermission('companies', 'create'), createCompany);
router.put('/:id', checkModulePermission('companies', 'edit'), updateCompany);
router.patch('/:id/status', checkModulePermission('companies', 'edit'), updateCompanyStatus);
router.patch('/:id/settings', checkModulePermission('companies', 'edit'), updateCompanySettings);
router.delete('/:id', checkModulePermission('companies', 'delete'), deleteCompany);

module.exports = router;
