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

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

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

export const fetchUserData = () => {
  return useMutation<
    PostGetUserDataReturn,
    BaseAxiosError,
    { token: string; region_id: number },
    PostGetUserDataReturn
  >({
    mutationKey: regionQueryKeys.getUserData(),
    mutationFn: async (variables) => {
      const response = await regionsApi.getUserData(variables.region_id, variables.token);
      return response.data;
    }
  });
};
