import type { GameState, PrestigeRequest } from "@elysium/types"; import { Hono } from "hono"; import { prisma } from "../db/client.js"; import { authMiddleware } from "../middleware/auth.js"; import { buildPostPrestigeState, isEligibleForPrestige, } from "../services/prestige.js"; export const prestigeRouter = new Hono(); prestigeRouter.use("*", authMiddleware); prestigeRouter.post("/", async (context) => { const discordId = context.get("discordId") as string; const body = await context.req.json(); const characterName = body.characterName?.trim(); if (!characterName) { return context.json({ error: "characterName is required" }, 400); } const record = await prisma.gameState.findUnique({ where: { discordId } }); if (!record) { return context.json({ error: "No save found" }, 404); } const state = record.state as unknown as GameState; if (!isEligibleForPrestige(state)) { return context.json( { error: "Not eligible for prestige — collect 1,000,000 total gold first" }, 400, ); } const { newState, newPrestigeData, runestonesEarned } = buildPostPrestigeState( state, characterName, ); const now = Date.now(); await prisma.gameState.update({ where: { discordId }, data: { state: newState as object, updatedAt: now }, }); await prisma.player.update({ where: { discordId }, data: { characterName, totalGoldEarned: 0, totalClicks: 0, lastSavedAt: now, }, }); return context.json({ runestones: runestonesEarned, newPrestigeCount: newPrestigeData.count, }); });