import { NextResponse } from "next/server" import { createServiceClient } from "@/lib/supabase" export async function PATCH( request: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params const body = await request.json().catch(() => ({})) const { status } = body as { status?: string } const STATUSES_VALIDOS = ["pendente", "confirmado", "realizado", "cancelado"] if (!status || !STATUSES_VALIDOS.includes(status)) { return NextResponse.json({ error: "Status inválido" }, { status: 400 }) } const supabase = createServiceClient() const { error } = await supabase .from("agendamentos") .update({ status, updated_at: new Date().toISOString() }) .eq("id", id) if (error) { return NextResponse.json({ error: error.message }, { status: 500 }) } return NextResponse.json({ ok: true, status }) }