import { useMutation } from '@tanstack/react-query';

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

import type { BaseAxiosError } from '../../../../types';

export const fetchSeriesData = () => {
  return useMutation<
    PostGetSeries,
    BaseAxiosError,
    { token: string | null; regions: string },
    PostGetSeries
  >({
    mutationKey: seriesQueryKeys.fetchSeriesData(),
    mutationFn: async (variables) => {
      const response = await seriesApi.getSeries(variables.token, variables.regions);
      return response.data;
    }
  });
};
