import { useQuery } from '@tanstack/react-query';
import { fetchPieces, fetchPiece } from '../api';
import { STALE_TIME } from '../lib/constants.js';

export function usePieceList() {
  return useQuery({ queryKey: ['pieces'], queryFn: fetchPieces, staleTime: STALE_TIME.SEMI_STATIC });
}

export function usePiece(name: string | undefined) {
  return useQuery({
    queryKey: ['piece', name],
    queryFn: () => fetchPiece(name!),
    enabled: !!name,
    staleTime: STALE_TIME.SEMI_STATIC,
  });
}
