import { regionQueryKeys } from '../regions-query-keys';
import { regionsApi, type PostGetUsersWhoVisitedDataReturn } from '../regions-api';

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

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

export const useGetUsersWhoVisitetRegionMutation = () => {
  return useMutation<
    PostGetUsersWhoVisitedDataReturn,
    BaseAxiosError,
    { id: number; page: number; sort?: string; age?: number; country?: string },
    PostGetUsersWhoVisitedDataReturn
  >({
    mutationKey: regionQueryKeys.getUsersWhoVisitedRegion(),
    mutationFn: async (variables) => {
      const response = await regionsApi.getUsersWhoVisitedRegion(
        variables.id,
        variables.page,
        variables.sort,
        variables.age,
        variables.country
      );
      return response.data;
    }
  });
};
