import { Router } from 'express';
import { AssetController } from '../controllers/asset.controller';
import { authenticate, requireRole } from '../middleware/auth.middleware';
import { upload } from '../middleware/upload.middleware';

const router = Router();
const assetController = new AssetController();

router.use(authenticate);

router.post('/upload', requireRole('ADMIN'), upload.single('file'), assetController.uploadAsset);
router.get('/scrape-case-study', requireRole('ADMIN'), assetController.scrapeCaseStudy);
router.get('/', assetController.listAssets);
router.patch('/bulk-share', requireRole('ADMIN'), assetController.bulkShareAssets);

// Asset groups endpoints
router.get('/groups/list', assetController.listAssetGroups);
router.post('/groups/create', requireRole('ADMIN'), assetController.createAssetGroup);
router.delete('/groups/:id', requireRole('ADMIN'), assetController.deleteAssetGroup);
router.patch('/groups/:id/add-assets', requireRole('ADMIN'), assetController.addAssetsToGroup);
router.patch('/groups/:id/remove-assets', requireRole('ADMIN'), assetController.removeAssetsFromGroup);

router.get('/:id', assetController.getAsset);
router.patch('/:id', requireRole('ADMIN'), assetController.updateAsset);
router.post('/:id/share', requireRole('ADMIN'), assetController.shareAsset);
router.post('/:id/unshare', requireRole('ADMIN'), assetController.unshareAsset);
router.post('/:id/download', assetController.incrementDownload);
router.delete('/:id', requireRole('ADMIN'), assetController.deleteAsset);

// Download permission request management
router.post('/:id/request-download', assetController.requestDownload);
router.post('/:id/approve-download/:requestId', requireRole('ADMIN'), assetController.approveDownload);
router.post('/:id/reject-download/:requestId', requireRole('ADMIN'), assetController.rejectDownload);

export default router;
