import { prisma } from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function POST(request: Request) {
  try {
    const body = await request.json()
    const {
      employeeId,
      employeeName,
      fromRole,
      toRole,
      fromDept,
      toDept,
      authorizedByName,
      notes
    } = body

    await prisma.promotionRecord.create({
      data: {
        employeeId,
        fromRole,
        toRole,
        fromDept,
        toDept,
        authorizedBy: authorizedByName,
        notes
      }
    })
    
    return NextResponse.json({ success: true })
  } catch (error) {
    console.error('Error promoting employee:', error)
    return NextResponse.json({ error: 'Failed to promote employee' }, { status: 500 })
  }
}