"use server";

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

export async function setEmailNotificationsEnabledAction(enabled: boolean) {
  const clientId = await getSessionClientId();
  if (!clientId) return;
  await connectDB();
  await Client.findByIdAndUpdate(clientId, { emailNotificationsEnabled: enabled });
  revalidatePath("/[locale]/account/profile", "page");
}
