import { useServerSuspenseQuery, useServerQuery } from "@/lib/tanstack-query/hooks";
import { getTeam, getTeamMatches, getTeamStats } from "./server";

export const teamKeys = {
  list: ['teams', 'list'] as const,
  details: (id: string) => ['teams', 'details', id] as const,
  stats: (id: string) => ['teams', 'stats', id] as const,
  matches: (id: string) => ['teams', 'matches', id] as const,
};

export const teamQueries = {
  details: (id: string) => ({
    queryKey: teamKeys.details(id),
    queryFn: () => getTeam({ data: id }),
  }),
  stats: (id: string) => ({
    queryKey: teamKeys.stats(id),
    queryFn: () => getTeamStats({ data: id }),
  }),
  matches: (id: string) => ({
    queryKey: teamKeys.matches(id),
    queryFn: () => getTeamMatches({ data: id })
  })
};

export const useTeam = (id: string) =>
  useServerSuspenseQuery(teamQueries.details(id));

export const useTeamStats = (id: string) =>
  useServerQuery(teamQueries.stats(id));

export const useTeamMatches = (id: string) =>
  useServerQuery(teamQueries.matches(id));
