import { useQuery } from '@tanstack/vue-query'
import { getReconciliationHoldings, getReconciliationMismatches } from './api'

export const reconciliationKeys = {
  all: ['reconciliation'] as const,
  holdings: () => [...reconciliationKeys.all, 'holdings'] as const,
  mismatches: (dateFrom?: string, dateTo?: string) => [...reconciliationKeys.all, 'mismatches', { dateFrom, dateTo }] as const
}

export function useReconciliationHoldingsQuery() {
  return useQuery({
    queryKey: reconciliationKeys.holdings(),
    queryFn: getReconciliationHoldings,
    staleTime: 60_000,
    retry: 1
  })
}

export function useReconciliationMismatchesQuery(dateFrom?: string, dateTo?: string) {
  return useQuery({
    queryKey: reconciliationKeys.mismatches(dateFrom, dateTo),
    queryFn: () => getReconciliationMismatches({ dateFrom, dateTo }),
    staleTime: 60_000,
    retry: 1,
    enabled: Boolean(dateFrom && dateTo)
  })
}
