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

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

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

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