import { NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { getSession } from "@/lib/auth";

export async function PUT(
  req: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  const session = await getSession();
  if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });

  const { id } = await params;
  const body = await req.json();

  const updateData: Record<string, unknown> = {};
  if (body.message !== undefined) updateData.message = body.message;
  if (body.isActive !== undefined) updateData.isActive = body.isActive;

  const template = await prisma.reminderTemplate.update({
    where: { id, clinicId: session.id },
    data: updateData,
  });

  return NextResponse.json(template);
}
