'use client';

import { useQuery } from '@tanstack/react-query';
import { api } from '@/lib/api';

export const BALANCE_KEYS = {
  forStore: (storeId: string) => ['balance', storeId] as const,
};

export function useBalance(storeId: string | null | undefined) {
  return useQuery({
    queryKey: storeId ? BALANCE_KEYS.forStore(storeId) : ['balance', 'none'],
    queryFn: () => api.balance.getForStore(storeId!),
    enabled: Boolean(storeId),
    staleTime: 30_000,
  });
}
