const express = require('express');
const { query, param } = require('express-validator');
const notificationController = require('../controllers/notificationController');
const { authenticateUser } = require('../middleware/auth');

const router = express.Router();

/**
 * Notification Routes
 * All routes require user authentication
 */

/**
 * @route   GET /api/v1/notifications
 * @desc    Get user's notifications with filtering and pagination
 * @access  Private (User)
 */
router.get(
  '/',
  authenticateUser,
  [
    query('page').optional().isInt({ min: 1 }).withMessage('Page must be a positive integer'),
    query('limit').optional().isInt({ min: 1, max: 100 }).withMessage('Limit must be between 1 and 100'),
    query('type')
      .optional()
      .isIn(['system', 'activity', 'service'])
      .withMessage('Type must be one of: system, activity, service'),
  ],
  notificationController.getNotifications
);

/**
 * @route   GET /api/v1/notifications/unread-count
 * @desc    Get unread notification counts by type
 * @access  Private (User)
 */
router.get(
  '/unread-count',
  authenticateUser,
  notificationController.getUnreadCounts
);

/**
 * @route   PUT /api/v1/notifications/read-all
 * @desc    Mark all notifications as read
 * @access  Private (User)
 */
router.put(
  '/read-all',
  authenticateUser,
  notificationController.markAllAsRead
);

/**
 * @route   PUT /api/v1/notifications/:id/read
 * @desc    Mark notification as read
 * @access  Private (User)
 */
router.put(
  '/:id/read',
  authenticateUser,
  [param('id').isUUID().withMessage('Notification ID must be a valid UUID')],
  notificationController.markAsRead
);

/**
 * @route   DELETE /api/v1/notifications/:id
 * @desc    Delete notification
 * @access  Private (User)
 */
router.delete(
  '/:id',
  authenticateUser,
  [param('id').isUUID().withMessage('Notification ID must be a valid UUID')],
  notificationController.deleteNotification
);

module.exports = router;
