import { Router } from 'express';
import multer from 'multer';
import nextcloudController from '../controllers/nextcloud.controller';
import { authenticate } from '../middleware/auth.middleware';

const router = Router();
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 50 * 1024 * 1024 } });

router.get('/', authenticate, nextcloudController.getConversations.bind(nextcloudController));
router.post('/connect', authenticate, nextcloudController.initiateConnect.bind(nextcloudController));
router.post('/poll', authenticate, nextcloudController.pollConnect.bind(nextcloudController));
router.delete('/connect', authenticate, nextcloudController.disconnect.bind(nextcloudController));

router.get('/rooms', authenticate, nextcloudController.getRooms.bind(nextcloudController));
router.get('/rooms/:token/messages', authenticate, nextcloudController.getMessages.bind(nextcloudController));
router.post('/rooms/:token/messages', authenticate, nextcloudController.sendMessage.bind(nextcloudController));
router.post('/rooms/:token/files', authenticate, upload.single('file'), nextcloudController.uploadFile.bind(nextcloudController));
router.post('/rooms/:token/read', authenticate, nextcloudController.markRoomAsRead.bind(nextcloudController));

router.get('/files/:fileId/download', authenticate, nextcloudController.downloadFile.bind(nextcloudController));
router.get('/files/:fileId/preview', authenticate, nextcloudController.getFilePreview.bind(nextcloudController));

router.get('/users', authenticate, nextcloudController.searchUsers.bind(nextcloudController));
router.post('/rooms', authenticate, nextcloudController.createRoom.bind(nextcloudController));
router.get('/rooms/:token/messages/:messageId/reactions', authenticate, nextcloudController.getReactions.bind(nextcloudController));
router.post('/rooms/:token/messages/:messageId/reactions', authenticate, nextcloudController.addReaction.bind(nextcloudController));
router.delete('/rooms/:token/messages/:messageId/reactions', authenticate, nextcloudController.removeReaction.bind(nextcloudController));
router.get('/rooms/:token/polls/:pollId', authenticate, nextcloudController.getPoll.bind(nextcloudController));

export default router;
