import { useQuery } from '@tanstack/react-query';
import { transferApi, type SearchTransferListingsParams } from '@/lib/chuyen-nhuong-api';

export const transferKeys = {
  all: ['transfer'] as const,
  search: (params: SearchTransferListingsParams) => ['transfer', 'search', params] as const,
  detail: (id: string) => ['transfer', 'detail', id] as const,
  stats: () => ['transfer', 'stats'] as const,
};

export function useTransferListingsSearch(params: SearchTransferListingsParams = {}) {
  return useQuery({
    queryKey: transferKeys.search(params),
    queryFn: () => transferApi.search(params),
  });
}

export function useTransferListingDetail(id: string) {
  return useQuery({
    queryKey: transferKeys.detail(id),
    queryFn: () => transferApi.getById(id),
    enabled: !!id,
  });
}

export function useTransferStats() {
  return useQuery({
    queryKey: transferKeys.stats(),
    queryFn: () => transferApi.getStats(),
    staleTime: 5 * 60 * 1000,
  });
}
