import { NextResponse } from "next/server";
import { markRead, markDismissed } from "@/lib/notifications";

export async function PATCH(
  request: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const { id } = await params;
    const body = await request.json();
    const { read, dismissed } = body as { read?: boolean; dismissed?: boolean };

    if (dismissed) {
      markDismissed(id);
    } else if (read) {
      markRead(id);
    }

    return NextResponse.json({ ok: true });
  } catch (err) {
    return NextResponse.json({ error: err instanceof Error ? err.message : "Unknown error" }, { status: 500 });
  }
}
