import { Router } from 'express';
import { messengerController } from '../controllers/messengerController';
import { authenticateToken } from '../middleware/authMiddleware';
import { uploadMessengerFile } from '../config/multerMessengerConfig';

const router = Router();

// All messenger routes require authentication
router.use(authenticateToken);

// GET /api/messenger/rooms - Get my rooms
router.get('/rooms', (req, res) => messengerController.getRooms(req, res));

// POST /api/messenger/rooms - Create a room
router.post('/rooms', (req, res) => messengerController.createRoom(req, res));

// GET /api/messenger/rooms/:roomId/messages - Get messages
router.get('/rooms/:roomId/messages', (req, res) => messengerController.getMessages(req, res));

// POST /api/messenger/rooms/:roomId/messages - Send message
router.post('/rooms/:roomId/messages', (req, res) => messengerController.sendMessage(req, res));

// POST /api/messenger/rooms/:roomId/read - Mark as read
router.post('/rooms/:roomId/read', (req, res) => messengerController.markAsRead(req, res));

// PUT /api/messenger/rooms/:roomId - Update room
router.put('/rooms/:roomId', (req, res) => messengerController.updateRoom(req, res));

// POST /api/messenger/files/upload - Upload files
router.post(
  '/files/upload',
  uploadMessengerFile.array('files', 10),
  (req, res) => messengerController.uploadFile(req, res)
);

// GET /api/messenger/files/:fileId - Download file
router.get('/files/:fileId', (req, res) => messengerController.downloadFile(req, res));

// GET /api/messenger/users - Get company users
router.get('/users', (req, res) => messengerController.getCompanyUsers(req, res));

// GET /api/messenger/unread - Get unread count
router.get('/unread', (req, res) => messengerController.getUnreadCount(req, res));

export default router;
