"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const zod_1 = require("zod");
const notificationController_1 = require("./notificationController");
const validation_middleware_1 = require("../api/middleware/validation.middleware");
const rbac_middleware_1 = require("../api/middleware/rbac.middleware");
const rateLimit_middleware_1 = require("../api/middleware/rateLimit.middleware");
const rbac_service_1 = require("../api/services/rbac.service");
const notificationService_1 = require("./notificationService");
const router = (0, express_1.Router)();
const notificationController = new notificationController_1.NotificationController();
// Validation schemas
const GetNotificationsSchema = zod_1.z.object({
    page: zod_1.z.coerce.number().int().min(1).optional(),
    limit: zod_1.z.coerce.number().int().min(1).max(100).optional(),
    unreadOnly: zod_1.z.coerce.boolean().optional()
});
const PreferencesSchema = zod_1.z.object({
    email: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        frequency: zod_1.z.enum(['instant', 'hourly', 'daily', 'weekly']),
        types: zod_1.z.array(zod_1.z.nativeEnum(notificationService_1.NotificationType))
    }).optional(),
    realtime: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        types: zod_1.z.array(zod_1.z.nativeEnum(notificationService_1.NotificationType)),
        sound: zod_1.z.boolean(),
        desktop: zod_1.z.boolean()
    }).optional(),
    doNotDisturb: zod_1.z.object({
        enabled: zod_1.z.boolean(),
        startTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/).optional(),
        endTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/).optional(),
        timezone: zod_1.z.string().optional()
    }).optional()
});
const SubscriptionSchema = zod_1.z.object({
    types: zod_1.z.array(zod_1.z.nativeEnum(notificationService_1.NotificationType)).min(1)
});
const TestNotificationSchema = zod_1.z.object({
    userId: zod_1.z.string().uuid(),
    type: zod_1.z.nativeEnum(notificationService_1.NotificationType).optional(),
    priority: zod_1.z.nativeEnum(notificationService_1.NotificationPriority).optional(),
    title: zod_1.z.string().max(200).optional(),
    message: zod_1.z.string().max(1000).optional()
});
const CleanupSchema = zod_1.z.object({
    daysToKeep: zod_1.z.number().int().min(1).max(365).optional()
});
/**
 * @route   GET /api/notifications
 * @desc    Get user's notifications
 * @access  Protected
 */
router.get('/', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.generalLimiter, (0, validation_middleware_1.validate)(GetNotificationsSchema, 'query'), (req, res) => notificationController.getNotifications(req, res));
/**
 * @route   PUT /api/notifications/:notificationId/read
 * @desc    Mark notification as read
 * @access  Protected
 */
router.put('/:notificationId/read', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(zod_1.z.object({ notificationId: zod_1.z.string().uuid() }), 'params'), (req, res) => notificationController.markAsRead(req, res));
/**
 * @route   PUT /api/notifications/read-all
 * @desc    Mark all notifications as read
 * @access  Protected
 */
router.put('/read-all', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.strictLimiter, (req, res) => notificationController.markAllAsRead(req, res));
/**
 * @route   GET /api/notifications/preferences
 * @desc    Get notification preferences
 * @access  Protected
 */
router.get('/preferences', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.generalLimiter, (req, res) => notificationController.getPreferences(req, res));
/**
 * @route   PUT /api/notifications/preferences
 * @desc    Update notification preferences
 * @access  Protected
 */
router.put('/preferences', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(PreferencesSchema, 'body'), (req, res) => notificationController.updatePreferences(req, res));
/**
 * @route   POST /api/notifications/subscribe
 * @desc    Subscribe to notification types
 * @access  Protected
 */
router.post('/subscribe', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(SubscriptionSchema, 'body'), (req, res) => notificationController.subscribe(req, res));
/**
 * @route   POST /api/notifications/unsubscribe
 * @desc    Unsubscribe from notification types
 * @access  Protected
 */
router.post('/unsubscribe', rbac_middleware_1.authenticateToken, rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(SubscriptionSchema, 'body'), (req, res) => notificationController.unsubscribe(req, res));
/**
 * @route   POST /api/notifications/test
 * @desc    Send test notification (admin only)
 * @access  Protected - Admin only
 */
router.post('/test', rbac_middleware_1.authenticateToken, (0, rbac_middleware_1.requirePermission)(rbac_service_1.Permission.MANAGE_SYSTEM), rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(TestNotificationSchema, 'body'), (req, res) => notificationController.sendTestNotification(req, res));
/**
 * @route   POST /api/notifications/cleanup
 * @desc    Clean up old notifications (admin only)
 * @access  Protected - Admin only
 */
router.post('/cleanup', rbac_middleware_1.authenticateToken, (0, rbac_middleware_1.requirePermission)(rbac_service_1.Permission.MANAGE_SYSTEM), rateLimit_middleware_1.strictLimiter, (0, validation_middleware_1.validate)(CleanupSchema, 'body'), (req, res) => notificationController.cleanupNotifications(req, res));
exports.default = router;
//# sourceMappingURL=notificationRoutes.js.map