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

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

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

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

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

export const useAllEarnedBadges = () =>
  useServerSuspenseQuery(badgeQueries.allEarnedBadges());
