import express from 'express';
import { sendMessage, getUnreadMessages, markMessageAsRead, getMyPendingMessages, deleteMessage, archiveMessage, recipientDeleteMessage } from '../controllers/messageController.js';
import { extractUser } from '../middleware/roleMiddleware.js';

const router = express.Router();

// All routes require authentication
router.post('/', extractUser, sendMessage);
router.get('/unread', extractUser, getUnreadMessages);
router.get('/pending', extractUser, getMyPendingMessages);
router.patch('/:id/read', extractUser, markMessageAsRead);
router.patch('/:id/archive', extractUser, archiveMessage);
router.delete('/:id', extractUser, deleteMessage); // Sender side (if unread)
router.delete('/:id/recipient', extractUser, recipientDeleteMessage); // Recipient side

export default router;
