import { prisma } from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
  try {
    const { id } = await context.params
    const body = await request.json()
    const { newHash, resetBy } = body

    const user = await prisma.user.update({
      where: { id },
      data: {
        passwordHash: newHash,
        isFirstLogin: true,
        updatedAt: new Date()
      }
    })
    
    return NextResponse.json({ success: true, user })
  } catch (error) {
    console.error('Error resetting password:', error)
    return NextResponse.json({ error: 'Failed to reset password' }, { status: 500 })
  }
}