﻿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 kpi = await prisma.kPI.update({
      where: { id },
      data: {
        title: body.title,
        description: body.description,
        targetValue: body.targetValue,
        currentValue: body.currentValue,
        measurementMethod: body.measurementMethod,
        frequency: body.frequency,
        progress: body.progress,
        performanceScore: body.performanceScore,
        targetDeadline: body.targetDeadline ? new Date(body.targetDeadline) : null,
      }
    });
    
    return NextResponse.json(kpi);
  } catch (error) {
    console.error('Error updating KPI:', error);
    return NextResponse.json({ error: 'Failed to update KPI' }, { status: 500 });
  }
}
