import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';

export async function PATCH(
  request: NextRequest,
  context: { params: Promise<{ treeId: string }> }
) {
  try {
    const { treeId } = await context.params;
    const body = await request.json();
    const { isActive } = body;

    const updatedTree = await prisma.reminderTree.update({
      where: { id: treeId },
      data: { isActive }
    });

    return NextResponse.json(updatedTree);
  } catch (error) {
    console.error('Failed to update tree:', error);
    return NextResponse.json(
      { error: 'Failed to update tree' }, 
      { status: 500 }
    );
  }
}