import { getSession } from '@/lib/session'
import { reviveCharacter } from '@/lib/character-services'

export async function POST(request: Request) {
  const session = await getSession()
  if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
  let character = ''
  try {
    const body = await request.json()
    character = String(body.character ?? '')
  } catch {
    return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
  }
  return Response.json(await reviveCharacter(session.accountId, character))
}
