import { useServerSuspenseQuery } from "@/lib/tanstack-query/hooks";
import { getPlayerBadges, getAllBadges } from "./server";

export const badgeKeys = {
  playerBadges: (playerId: string) => ['badges', 'player', playerId],
  allBadges: () => ['badges', 'all'],
};

export const badgeQueries = {
  playerBadges: (playerId: string) => ({
    queryKey: badgeKeys.playerBadges(playerId),
    queryFn: async () => await getPlayerBadges({ data: playerId })
  }),
  allBadges: () => ({
    queryKey: badgeKeys.allBadges(),
    queryFn: async () => await getAllBadges()
  }),
};

export const usePlayerBadges = (playerId: string) =>
  useServerSuspenseQuery(badgeQueries.playerBadges(playerId));

export const useAllBadges = () =>
  useServerSuspenseQuery(badgeQueries.allBadges());
