import { seriesQueryKeys } from '../series-query-keys';
import { seriesApi, type PostGetItems } from '../series-api';

import { queryClient } from 'src/utils/queryClient';

export const fetchItemsForSeries = async (token: string, series_id: string) => {
  try {
    const data: PostGetItems = await queryClient.fetchQuery({
      queryKey: seriesQueryKeys.getItemsForSeries(token, series_id),
      queryFn: async () => {
        const response = await seriesApi.getItemsForSeries(token, series_id);
        return response.data;
      },
      gcTime: 0,
      staleTime: 0
    });

    return data;
  } catch (error) {
    console.error('Failed to fetch items for series:', error);
  }
};
