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

export async function PUT(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> | { id: string } }
) {
  try {
    const { id } = await params;
    const body = await request.json();
    
    const target = await prisma.quarterlyTarget.update({
      where: { id },
      data: {
        title: body.title,
        target: body.target,
        kpiMeasurement: body.kpiMeasurement,
        expectedOutcome: body.expectedOutcome,
        progress: body.progress,
        status: body.status,
        weight: body.weight,
      }
    });
    
    return NextResponse.json(target);
  } catch (error) {
    console.error('Error updating quarterly target:', error);
    return NextResponse.json({ error: 'Failed to update quarterly target' }, { status: 500 });
  }
}
