import { useQuery } from "@tanstack/react-query";
import { api, type PaginatedResponse } from "@/lib/api";
import type { Ta1Ack } from "@/types";

/**
 * Lists persisted TA1 (Interchange Acknowledgment) rows, newest
 * first. Mirrors `useAcks` but for the lower-level envelope ack.
 *
 * A TA1 is one row per inbound ISA/IEA interchange — distinct from
 * a 999, which is per-batch. Colorado Medicaid's Gainwell MFT
 * currently only ships 999s in the FromHPE path, but historically
 * they've sent TA1s, so the hook stays in the surface for when
 * they reappear.
 *
 * No in-memory fallback: there is no zustand sample-data path for
 * TA1s in v1. The hook is `enabled: api.isConfigured` so the page
 * treats an empty list as "no TA1s on file" rather than a
 * configuration error.
 */
export function useTa1Acks(params: { limit?: number } = {}) {
  return useQuery<PaginatedResponse<Ta1Ack>>({
    queryKey: ["ta1-acks", params],
    queryFn: () => api.listTa1Acks(params),
    enabled: api.isConfigured,
  });
}
