import { getSession } from '@/lib/session'
import { restoreCharacter } from '@/lib/restore-character'

/** Recupera un personaje borrado de la cuenta en sesión (si cumple las condiciones). */
export async function POST(request: Request) {
  const session = await getSession()
  if (!session.accountId || !session.username) {
    return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
  }
  let body: Record<string, unknown> = {}
  try {
    body = await request.json()
  } catch {
    return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
  }
  return Response.json(await restoreCharacter(session.accountId, Number(body.guid)))
}
