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

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

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

export const useGetUsersWhoTickesSeriesMutation = () => {
  return useMutation<
    PostGetUsersWhoVisitedDataReturn,
    BaseAxiosError,
    { token: string; id: number; page: number; sort?: string; age?: number; country?: string },
    PostGetUsersWhoVisitedDataReturn
  >({
    mutationKey: seriesQueryKeys.getUsersWhoTickedSeries(),
    mutationFn: async (variables) => {
      const response = await seriesApi.getUsersWhoTickedSeries(
        variables.token,
        variables.id,
        variables.page,
        variables.sort,
        variables.age,
        variables.country
      );
      return response.data;
    }
  });
};
