const express = require('express');
const {
  getAllLibraryItems,
  getLibraryByCompanyId,
  getLibraryItem,
  uploadLibraryItem,
  updateLibraryItem,
  deleteLibraryItem,
  uploadNewVersion,
  downloadLibraryItem,
  toggleFavorite,
  getFavorites,
  getLibraryStats,
  getCategories,
  getTags,
  shareLibraryItem,
  getUnseenCounts
} = require('../controllers/libraryController');

const upload = require("../middleware/upload");
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

//router.get('/stats', checkModulePermission('libraries', 'read'), getLibraryStats);
//router.get('/categories', checkModulePermission('libraries', 'read'), getCategories);
//router.get('/tags', checkModulePermission('libraries', 'read'), getTags);
//router.get('/favorites', checkModulePermission('libraries', 'read'), getFavorites);
router.get('/', checkModulePermission('libraries', 'read'), getAllLibraryItems);
router.get('/unseen-counts', checkModulePermission('libraries', 'read'), getUnseenCounts);
router.get('/:companyId', checkModulePermission('libraries', 'read'), getLibraryByCompanyId);
router.get('/:id', checkModulePermission('libraries', 'read'), getLibraryItem);
router.post('/', checkModulePermission('libraries', 'create'), upload.single("file"), uploadLibraryItem);
//router.post('/:id/version', checkModulePermission('libraries', 'edit'), uploadNewVersion);
router.get('/:id/download', checkModulePermission('libraries', 'export'), downloadLibraryItem);
router.get('/:id/share', checkModulePermission('libraries', 'share'), shareLibraryItem);
//router.post('/:id/favorite', toggleFavorite);
router.put('/:id', checkModulePermission('libraries', 'edit'), upload.single("file"), updateLibraryItem);
router.delete('/:id', checkModulePermission('libraries', 'delete'), deleteLibraryItem);

module.exports = router;