'use client';

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getPagosSinFactura, emitirFacturaPago } from '../api/facturacion';

export function usePagosSinFactura() {
  return useQuery({
    queryKey: ['pagos-sin-factura'],
    queryFn: () => getPagosSinFactura(),
    staleTime: 10 * 1000,
  });
}

export function useEmitirFacturaPago() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: (paymentId: string) => emitirFacturaPago(paymentId),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ['pagos-sin-factura'] });
    },
  });
}
