import { Router } from 'express';
import { systemController } from './system.controller.js';
import { authenticate, requireRoles } from '../../shared/middleware/auth.middleware.js';

const router = Router();

// All routes require authentication
router.use(authenticate);

// ========== MESSAGES (Chatter) ==========
router.get('/messages', (req, res, next) => systemController.getMessages(req, res, next));
router.get('/messages/record/:model/:recordId', (req, res, next) => systemController.getMessagesByRecord(req, res, next));
router.get('/messages/:id', (req, res, next) => systemController.getMessage(req, res, next));
router.post('/messages', (req, res, next) => systemController.createMessage(req, res, next));
router.delete('/messages/:id', (req, res, next) => systemController.deleteMessage(req, res, next));

// ========== FOLLOWERS ==========
router.get('/followers/:model/:recordId', (req, res, next) => systemController.getFollowers(req, res, next));
router.post('/followers', (req, res, next) => systemController.addFollower(req, res, next));
router.delete('/followers/:model/:recordId', (req, res, next) => systemController.removeFollower(req, res, next));

// ========== NOTIFICATIONS ==========
router.get('/notifications', requireRoles('admin', 'super_admin'), (req, res, next) =>
  systemController.getNotifications(req, res, next)
);
router.get('/notifications/me', (req, res, next) => systemController.getMyNotifications(req, res, next));
router.get('/notifications/me/count', (req, res, next) => systemController.getUnreadCount(req, res, next));
router.get('/notifications/:id', (req, res, next) => systemController.getNotification(req, res, next));
router.post('/notifications', requireRoles('admin', 'super_admin'), (req, res, next) =>
  systemController.createNotification(req, res, next)
);
router.post('/notifications/:id/read', (req, res, next) => systemController.markNotificationAsRead(req, res, next));
router.post('/notifications/read-all', (req, res, next) => systemController.markAllNotificationsAsRead(req, res, next));
router.delete('/notifications/:id', (req, res, next) => systemController.deleteNotification(req, res, next));

// ========== ACTIVITIES ==========
router.get('/activities', (req, res, next) => systemController.getActivities(req, res, next));
router.get('/activities/record/:model/:recordId', (req, res, next) => systemController.getActivitiesByRecord(req, res, next));
router.get('/activities/me', (req, res, next) => systemController.getMyActivities(req, res, next));
router.get('/activities/:id', (req, res, next) => systemController.getActivity(req, res, next));
router.post('/activities', (req, res, next) => systemController.createActivity(req, res, next));
router.put('/activities/:id', (req, res, next) => systemController.updateActivity(req, res, next));
router.post('/activities/:id/done', (req, res, next) => systemController.markActivityDone(req, res, next));
router.post('/activities/:id/cancel', (req, res, next) => systemController.cancelActivity(req, res, next));
router.post('/activities/:id/reschedule', (req, res, next) => systemController.rescheduleActivity(req, res, next));
router.delete('/activities/:id', (req, res, next) => systemController.deleteActivity(req, res, next));

export default router;
