import { prisma } from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function POST(request: Request) {
  try {
    const body = await request.json()
    const { deptName, hodUserId, assignedByName } = body

    const department = await prisma.department.findFirst({
      where: { name: deptName }
    })
    
    if (!department) {
      return NextResponse.json({ error: 'Department not found' }, { status: 404 })
    }
    
    await prisma.department.update({
      where: { id: department.id },
      data: { hodId: hodUserId }
    })
    
    return NextResponse.json({ success: true })
  } catch (error) {
    console.error('Error assigning HOD:', error)
    return NextResponse.json({ error: 'Failed to assign HOD' }, { status: 500 })
  }
}