"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationController = void 0;
const notificationService_1 = require("./notificationService");
/**
 * Notification Controller
 * Handles HTTP requests for notification management
 */
class NotificationController {
    /**
     * Get user's notifications
     */
    async getNotifications(req, res) {
        try {
            const userId = req.userId;
            const { page = 1, limit = 20, unreadOnly = false } = req.query;
            // This would normally query the database
            // For now, returning a placeholder response
            res.json({
                success: true,
                data: {
                    notifications: [],
                    pagination: {
                        page: Number(page),
                        limit: Number(limit),
                        total: 0
                    }
                }
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Mark notification as read
     */
    async markAsRead(req, res) {
        try {
            const { notificationId } = req.params;
            const userId = req.userId;
            await notificationService_1.notificationService.markNotificationAsRead(notificationId, userId);
            res.json({
                success: true,
                message: 'Notification marked as read'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Mark all notifications as read
     */
    async markAllAsRead(req, res) {
        try {
            const userId = req.userId;
            await notificationService_1.notificationService.markAllNotificationsAsRead(userId);
            res.json({
                success: true,
                message: 'All notifications marked as read'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Get notification preferences
     */
    async getPreferences(req, res) {
        try {
            const userId = req.userId;
            // This would normally fetch from database
            // For now, returning default preferences
            res.json({
                success: true,
                data: {
                    email: {
                        enabled: true,
                        frequency: 'instant',
                        types: Object.values(notificationService_1.NotificationType)
                    },
                    realtime: {
                        enabled: true,
                        types: Object.values(notificationService_1.NotificationType),
                        sound: true,
                        desktop: true
                    },
                    doNotDisturb: {
                        enabled: false
                    }
                }
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Update notification preferences
     */
    async updatePreferences(req, res) {
        try {
            const userId = req.userId;
            const preferences = req.body;
            await notificationService_1.notificationService.updateUserPreferences(userId, preferences);
            res.json({
                success: true,
                message: 'Preferences updated successfully'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Subscribe to notification types
     */
    async subscribe(req, res) {
        try {
            const userId = req.userId;
            const { types } = req.body;
            await notificationService_1.notificationService.subscribeToNotificationTypes(userId, types);
            res.json({
                success: true,
                message: 'Subscribed to notification types'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Unsubscribe from notification types
     */
    async unsubscribe(req, res) {
        try {
            const userId = req.userId;
            const { types } = req.body;
            await notificationService_1.notificationService.unsubscribeFromNotificationTypes(userId, types);
            res.json({
                success: true,
                message: 'Unsubscribed from notification types'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Send test notification (admin only)
     */
    async sendTestNotification(req, res) {
        try {
            const { userId, type, priority, title, message } = req.body;
            await notificationService_1.notificationService.sendNotification(userId, {
                type: type || notificationService_1.NotificationType.TASK_UPDATED,
                priority: priority || notificationService_1.NotificationPriority.MEDIUM,
                title: title || 'Test Notification',
                message: message || 'This is a test notification'
            });
            res.json({
                success: true,
                message: 'Test notification sent'
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
    /**
     * Clean up old notifications (admin only)
     */
    async cleanupNotifications(req, res) {
        try {
            const { daysToKeep = 30 } = req.body;
            const deleted = await notificationService_1.notificationService.cleanupOldNotifications(daysToKeep);
            res.json({
                success: true,
                message: `Cleaned up ${deleted} old notifications`
            });
        }
        catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
}
exports.NotificationController = NotificationController;
//# sourceMappingURL=notificationController.js.map