/**
 * API: Mark All Notifications as Read
 * POST /api/notifications/read-all - Mark all notifications as read for user
 */

import type { NextApiRequest, NextApiResponse } from 'next';
import { getNotificationService } from '../../../lib/notifications';

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  try {
    const notificationService = getNotificationService();
    // In production, get userId from session/auth
    const userId = req.body.userId || 'demo-user';

    const count = notificationService.markAllAsRead(userId);

    return res.status(200).json({
      success: true,
      data: {
        markedAsRead: count
      }
    });
  } catch (error: any) {
    return res.status(500).json({
      success: false,
      error: error.message
    });
  }
}
