import { getUserScore, getRecentScoreEvents } from "../../db/scores";

// GET /api/scores/me – eigener Score + Tier + letzte Events
export default defineEventHandler(async (event) => {
  const user = await requireUser(event);

  const [score, events] = await Promise.all([
    getUserScore(user.id),
    getRecentScoreEvents(user.id, 20),
  ]);

  return {
    total_points: score?.totalPoints ?? 0,
    tier: score?.tier ?? "beginner",
    recent_events: events.map((e) => ({
      event_type: e.eventType,
      points: e.points,
      created_at: e.createdAt,
      meta: e.meta,
    })),
  };
});
