"use server";

import { revalidatePath } from "next/cache";
import { getSessionClientId } from "@/lib/auth";
import { connectDB } from "@/lib/db";
import { Notification } from "@/models/Notification";

export async function markNotificationReadAction(notificationId: string) {
  const clientId = await getSessionClientId();
  if (!clientId) return;
  await connectDB();
  await Notification.updateOne({ _id: notificationId, recipientId: clientId }, { $set: { read: true } });
}

export async function markAllNotificationsReadAction() {
  const clientId = await getSessionClientId();
  if (!clientId) return;
  await connectDB();
  await Notification.updateMany({ recipientId: clientId, read: false }, { $set: { read: true } });
  revalidatePath("/de/admin/notifications");
  revalidatePath("/[locale]/account/notifications", "page");
}
