import { useQuery } from '@tanstack/react-query';
import { getDisputeItems } from '@/lib/dashboard/dashboard-api';
import {
  getAllScore,
  getMonthlyData,
  totalAccount,
  getReportDate,
} from '@/lib/dashboard/dashboard-api';

type Bureau = 'transunion' | 'equifax' | 'experian';

export const useCreditReport = (
  customerId: string | number,
  bureau: Bureau,
  reportDate?: string
) => {
  return useQuery({
    queryKey: ['credit-report', customerId, bureau, reportDate],

    queryFn: async () => {
      if (!customerId) return null;

      const [monthlyData, allScore, totalAccounts, reportDates] =
        await Promise.all([
          getMonthlyData(customerId),
          getAllScore(customerId, reportDate),
          totalAccount(customerId, reportDate),
          getReportDate(customerId, bureau),
        ]);

      return {
        monthlyData,
        allScore,
        totalAccounts,
        reportDates: reportDates.data.results,
      };
    },

    enabled: !!customerId, // don't run until we have ID
    staleTime: 1000 * 60 * 5, //  5 min cache (same as your example)
    refetchOnWindowFocus: false, // optional (prevents annoying refetch)
  });
};
export const useDisputeItems = (
  customerId: string | number,
  type: string,
  page: number = 1,
  itemType: number | string = 0,
  childTypeId: number | string = 0,
  search: string = ''
) => {
  return useQuery({
    queryKey: ['dispute-items', customerId, type, page, itemType, childTypeId, search],
    queryFn: async () => {
      const res = await getDisputeItems(customerId, type, page, itemType, childTypeId, search);
      return res;
    },
    staleTime: 1000 * 60 * 5,
  });
};


